blob: 9f9f4a7b1cddb69534c1727a6f4cc900b3732864 [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"
Jim Ingham969795f2011-09-21 01:17:1319#include "lldb/Breakpoint/BreakpointResolverFileRegex.h"
Chris Lattner30fdc8d2010-06-08 16:52:2420#include "lldb/Breakpoint/BreakpointResolverName.h"
Greg Clayton8b2fe6d2010-12-14 02:59:5921#include "lldb/Core/Debugger.h"
Chris Lattner30fdc8d2010-06-08 16:52:2422#include "lldb/Core/Event.h"
23#include "lldb/Core/Log.h"
Caroline Tice969ed3d12011-05-02 20:41:4624#include "lldb/Core/StreamAsynchronousIO.h"
Chris Lattner30fdc8d2010-06-08 16:52:2425#include "lldb/Core/StreamString.h"
Greg Clayton8b2fe6d2010-12-14 02:59:5926#include "lldb/Core/Timer.h"
27#include "lldb/Core/ValueObject.h"
Greg Claytoneb0103f2011-04-07 22:46:3528#include "lldb/Expression/ClangUserExpression.h"
Chris Lattner30fdc8d2010-06-08 16:52:2429#include "lldb/Host/Host.h"
Jim Ingham9575d842011-03-11 03:53:5930#include "lldb/Interpreter/CommandInterpreter.h"
31#include "lldb/Interpreter/CommandReturnObject.h"
Chris Lattner30fdc8d2010-06-08 16:52:2432#include "lldb/lldb-private-log.h"
33#include "lldb/Symbol/ObjectFile.h"
34#include "lldb/Target/Process.h"
Greg Clayton8b2fe6d2010-12-14 02:59:5935#include "lldb/Target/StackFrame.h"
Jim Ingham9575d842011-03-11 03:53:5936#include "lldb/Target/Thread.h"
37#include "lldb/Target/ThreadSpec.h"
Chris Lattner30fdc8d2010-06-08 16:52:2438
39using namespace lldb;
40using namespace lldb_private;
41
42//----------------------------------------------------------------------
43// Target constructor
44//----------------------------------------------------------------------
Greg Clayton32e0a752011-03-30 18:16:5145Target::Target(Debugger &debugger, const ArchSpec &target_arch, const lldb::PlatformSP &platform_sp) :
46 Broadcaster ("lldb.target"),
47 ExecutionContextScope (),
Greg Claytondbe54502010-11-19 03:46:0148 TargetInstanceSettings (*GetSettingsController()),
Greg Clayton66111032010-06-23 01:19:2949 m_debugger (debugger),
Greg Clayton32e0a752011-03-30 18:16:5150 m_platform_sp (platform_sp),
Greg Claytonaf67cec2010-12-20 20:49:2351 m_mutex (Mutex::eMutexTypeRecursive),
Greg Clayton32e0a752011-03-30 18:16:5152 m_arch (target_arch),
53 m_images (),
Greg Claytonf5e56de2010-09-14 23:36:4054 m_section_load_list (),
Chris Lattner30fdc8d2010-06-08 16:52:2455 m_breakpoint_list (false),
56 m_internal_breakpoint_list (true),
Johnny Chen1d6bad02011-09-06 20:05:2557 m_watchpoint_location_list (),
Greg Clayton32e0a752011-03-30 18:16:5158 m_process_sp (),
59 m_search_filter_sp (),
Chris Lattner30fdc8d2010-06-08 16:52:2460 m_image_search_paths (ImageSearchPathsChanged, this),
Greg Clayton8b2fe6d2010-12-14 02:59:5961 m_scratch_ast_context_ap (NULL),
Jim Ingham9575d842011-03-11 03:53:5962 m_persistent_variables (),
Jim Inghame37d6052011-09-13 00:29:5663 m_source_manager(*this),
Greg Clayton32e0a752011-03-30 18:16:5164 m_stop_hooks (),
Jim Ingham6026ca32011-05-12 02:06:1465 m_stop_hook_next_id (0),
66 m_suppress_stop_hooks (false)
Chris Lattner30fdc8d2010-06-08 16:52:2467{
Greg Claytoncfd1ace2010-10-31 03:01:0668 SetEventName (eBroadcastBitBreakpointChanged, "breakpoint-changed");
69 SetEventName (eBroadcastBitModulesLoaded, "modules-loaded");
70 SetEventName (eBroadcastBitModulesUnloaded, "modules-unloaded");
71
Greg Clayton2d4edfb2010-11-06 01:53:3072 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner30fdc8d2010-06-08 16:52:2473 if (log)
74 log->Printf ("%p Target::Target()", this);
75}
76
77//----------------------------------------------------------------------
78// Destructor
79//----------------------------------------------------------------------
80Target::~Target()
81{
Greg Clayton2d4edfb2010-11-06 01:53:3082 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner30fdc8d2010-06-08 16:52:2483 if (log)
84 log->Printf ("%p Target::~Target()", this);
85 DeleteCurrentProcess ();
86}
87
88void
Caroline Ticeceb6b132010-10-26 03:11:1389Target::Dump (Stream *s, lldb::DescriptionLevel description_level)
Chris Lattner30fdc8d2010-06-08 16:52:2490{
Greg Clayton89411422010-10-08 00:21:0591// s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
Caroline Ticeceb6b132010-10-26 03:11:1392 if (description_level != lldb::eDescriptionLevelBrief)
93 {
94 s->Indent();
95 s->PutCString("Target\n");
96 s->IndentMore();
Greg Clayton93aa84e2010-10-29 04:59:3597 m_images.Dump(s);
98 m_breakpoint_list.Dump(s);
99 m_internal_breakpoint_list.Dump(s);
100 s->IndentLess();
Caroline Ticeceb6b132010-10-26 03:11:13101 }
102 else
103 {
Greg Claytonaa149cb2011-08-11 02:48:45104 Module *exe_module = GetExecutableModulePointer();
105 if (exe_module)
106 s->PutCString (exe_module->GetFileSpec().GetFilename().GetCString());
Jim Ingham48028b62011-05-12 01:12:28107 else
108 s->PutCString ("No executable module.");
Caroline Ticeceb6b132010-10-26 03:11:13109 }
Chris Lattner30fdc8d2010-06-08 16:52:24110}
111
112void
113Target::DeleteCurrentProcess ()
114{
115 if (m_process_sp.get())
116 {
Greg Clayton17f69202010-09-14 23:52:43117 m_section_load_list.Clear();
Chris Lattner30fdc8d2010-06-08 16:52:24118 if (m_process_sp->IsAlive())
119 m_process_sp->Destroy();
Jim Inghamd0a3e12b2011-02-16 17:54:55120
121 m_process_sp->Finalize();
Chris Lattner30fdc8d2010-06-08 16:52:24122
123 // Do any cleanup of the target we need to do between process instances.
124 // NB It is better to do this before destroying the process in case the
125 // clean up needs some help from the process.
126 m_breakpoint_list.ClearAllBreakpointSites();
127 m_internal_breakpoint_list.ClearAllBreakpointSites();
Johnny Chen86364b42011-09-20 23:28:55128 m_watchpoint_location_list.RemoveAll();
Chris Lattner30fdc8d2010-06-08 16:52:24129 m_process_sp.reset();
130 }
131}
132
133const lldb::ProcessSP &
134Target::CreateProcess (Listener &listener, const char *plugin_name)
135{
136 DeleteCurrentProcess ();
137 m_process_sp.reset(Process::FindPlugin(*this, plugin_name, listener));
138 return m_process_sp;
139}
140
141const lldb::ProcessSP &
142Target::GetProcessSP () const
143{
144 return m_process_sp;
145}
146
147lldb::TargetSP
148Target::GetSP()
149{
Greg Clayton4d122c42011-09-17 08:33:22150 // This object contains an instrusive ref count base class so we can
151 // easily make a shared pointer to this object
152 return TargetSP(this);
Chris Lattner30fdc8d2010-06-08 16:52:24153}
154
Greg Clayton3418c852011-08-10 02:10:13155void
156Target::Destroy()
157{
158 Mutex::Locker locker (m_mutex);
159 DeleteCurrentProcess ();
160 m_platform_sp.reset();
161 m_arch.Clear();
162 m_images.Clear();
163 m_section_load_list.Clear();
164 const bool notify = false;
165 m_breakpoint_list.RemoveAll(notify);
166 m_internal_breakpoint_list.RemoveAll(notify);
167 m_last_created_breakpoint.reset();
168 m_search_filter_sp.reset();
169 m_image_search_paths.Clear(notify);
170 m_scratch_ast_context_ap.reset();
171 m_persistent_variables.Clear();
172 m_stop_hooks.clear();
173 m_stop_hook_next_id = 0;
174 m_suppress_stop_hooks = false;
175}
176
177
Chris Lattner30fdc8d2010-06-08 16:52:24178BreakpointList &
179Target::GetBreakpointList(bool internal)
180{
181 if (internal)
182 return m_internal_breakpoint_list;
183 else
184 return m_breakpoint_list;
185}
186
187const BreakpointList &
188Target::GetBreakpointList(bool internal) const
189{
190 if (internal)
191 return m_internal_breakpoint_list;
192 else
193 return m_breakpoint_list;
194}
195
196BreakpointSP
197Target::GetBreakpointByID (break_id_t break_id)
198{
199 BreakpointSP bp_sp;
200
201 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
202 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
203 else
204 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
205
206 return bp_sp;
207}
208
209BreakpointSP
Jim Ingham969795f2011-09-21 01:17:13210Target::CreateBreakpoint (const FileSpecList *containingModules,
211 const FileSpec &file,
212 RegularExpression &source_regex,
213 bool internal)
Chris Lattner30fdc8d2010-06-08 16:52:24214{
Jim Ingham969795f2011-09-21 01:17:13215 SearchFilterSP filter_sp(GetSearchFilterForModuleList (containingModules));
216 BreakpointResolverSP resolver_sp(new BreakpointResolverFileRegex (NULL, file, source_regex));
217 return CreateBreakpoint (filter_sp, resolver_sp, internal);
218}
219
220
221BreakpointSP
222Target::CreateBreakpoint (const FileSpecList *containingModules, const FileSpec &file, uint32_t line_no, bool check_inlines, bool internal)
223{
224 SearchFilterSP filter_sp(GetSearchFilterForModuleList (containingModules));
Chris Lattner30fdc8d2010-06-08 16:52:24225 BreakpointResolverSP resolver_sp(new BreakpointResolverFileLine (NULL, file, line_no, check_inlines));
226 return CreateBreakpoint (filter_sp, resolver_sp, internal);
227}
228
229
230BreakpointSP
Greg Clayton1b72fcb2010-08-24 00:45:41231Target::CreateBreakpoint (lldb::addr_t addr, bool internal)
Chris Lattner30fdc8d2010-06-08 16:52:24232{
Chris Lattner30fdc8d2010-06-08 16:52:24233 Address so_addr;
234 // Attempt to resolve our load address if possible, though it is ok if
235 // it doesn't resolve to section/offset.
236
Greg Clayton1b72fcb2010-08-24 00:45:41237 // Try and resolve as a load address if possible
Greg Claytonf5e56de2010-09-14 23:36:40238 m_section_load_list.ResolveLoadAddress(addr, so_addr);
Greg Clayton1b72fcb2010-08-24 00:45:41239 if (!so_addr.IsValid())
240 {
241 // The address didn't resolve, so just set this as an absolute address
242 so_addr.SetOffset (addr);
243 }
244 BreakpointSP bp_sp (CreateBreakpoint(so_addr, internal));
Chris Lattner30fdc8d2010-06-08 16:52:24245 return bp_sp;
246}
247
248BreakpointSP
249Target::CreateBreakpoint (Address &addr, bool internal)
250{
251 TargetSP target_sp = this->GetSP();
252 SearchFilterSP filter_sp(new SearchFilter (target_sp));
253 BreakpointResolverSP resolver_sp (new BreakpointResolverAddress (NULL, addr));
254 return CreateBreakpoint (filter_sp, resolver_sp, internal);
255}
256
257BreakpointSP
Jim Ingham969795f2011-09-21 01:17:13258Target::CreateBreakpoint (const FileSpecList *containingModules,
Greg Claytond16e1e52011-07-12 17:06:17259 const char *func_name,
260 uint32_t func_name_type_mask,
261 bool internal,
262 LazyBool skip_prologue)
Chris Lattner30fdc8d2010-06-08 16:52:24263{
Greg Clayton0c5cd902010-06-28 21:30:43264 BreakpointSP bp_sp;
265 if (func_name)
266 {
Jim Ingham969795f2011-09-21 01:17:13267 SearchFilterSP filter_sp(GetSearchFilterForModuleList (containingModules));
Greg Claytond16e1e52011-07-12 17:06:17268
269 BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL,
270 func_name,
271 func_name_type_mask,
272 Breakpoint::Exact,
273 skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
Greg Clayton0c5cd902010-06-28 21:30:43274 bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal);
275 }
276 return bp_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24277}
278
279
280SearchFilterSP
281Target::GetSearchFilterForModule (const FileSpec *containingModule)
282{
283 SearchFilterSP filter_sp;
284 lldb::TargetSP target_sp = this->GetSP();
285 if (containingModule != NULL)
286 {
287 // TODO: We should look into sharing module based search filters
288 // across many breakpoints like we do for the simple target based one
289 filter_sp.reset (new SearchFilterByModule (target_sp, *containingModule));
290 }
291 else
292 {
293 if (m_search_filter_sp.get() == NULL)
294 m_search_filter_sp.reset (new SearchFilter (target_sp));
295 filter_sp = m_search_filter_sp;
296 }
297 return filter_sp;
298}
299
Jim Ingham969795f2011-09-21 01:17:13300SearchFilterSP
301Target::GetSearchFilterForModuleList (const FileSpecList *containingModules)
302{
303 SearchFilterSP filter_sp;
304 lldb::TargetSP target_sp = this->GetSP();
305 if (containingModules && containingModules->GetSize() != 0)
306 {
307 // TODO: We should look into sharing module based search filters
308 // across many breakpoints like we do for the simple target based one
309 filter_sp.reset (new SearchFilterByModuleList (target_sp, *containingModules));
310 }
311 else
312 {
313 if (m_search_filter_sp.get() == NULL)
314 m_search_filter_sp.reset (new SearchFilter (target_sp));
315 filter_sp = m_search_filter_sp;
316 }
317 return filter_sp;
318}
319
Chris Lattner30fdc8d2010-06-08 16:52:24320BreakpointSP
Jim Ingham969795f2011-09-21 01:17:13321Target::CreateBreakpoint (const FileSpecList *containingModules,
Greg Claytond16e1e52011-07-12 17:06:17322 RegularExpression &func_regex,
323 bool internal,
324 LazyBool skip_prologue)
Chris Lattner30fdc8d2010-06-08 16:52:24325{
Jim Ingham969795f2011-09-21 01:17:13326 SearchFilterSP filter_sp(GetSearchFilterForModuleList (containingModules));
Greg Claytond16e1e52011-07-12 17:06:17327 BreakpointResolverSP resolver_sp(new BreakpointResolverName (NULL,
328 func_regex,
329 skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue));
Chris Lattner30fdc8d2010-06-08 16:52:24330
331 return CreateBreakpoint (filter_sp, resolver_sp, internal);
332}
333
334BreakpointSP
335Target::CreateBreakpoint (SearchFilterSP &filter_sp, BreakpointResolverSP &resolver_sp, bool internal)
336{
337 BreakpointSP bp_sp;
338 if (filter_sp && resolver_sp)
339 {
340 bp_sp.reset(new Breakpoint (*this, filter_sp, resolver_sp));
341 resolver_sp->SetBreakpoint (bp_sp.get());
342
343 if (internal)
Greg Clayton9fed0d82010-07-23 23:33:17344 m_internal_breakpoint_list.Add (bp_sp, false);
Chris Lattner30fdc8d2010-06-08 16:52:24345 else
Greg Clayton9fed0d82010-07-23 23:33:17346 m_breakpoint_list.Add (bp_sp, true);
Chris Lattner30fdc8d2010-06-08 16:52:24347
Greg Clayton2d4edfb2010-11-06 01:53:30348 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24349 if (log)
350 {
351 StreamString s;
352 bp_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose);
353 log->Printf ("Target::%s (internal = %s) => break_id = %s\n", __FUNCTION__, internal ? "yes" : "no", s.GetData());
354 }
355
Chris Lattner30fdc8d2010-06-08 16:52:24356 bp_sp->ResolveBreakpoint();
357 }
Jim Ingham36f3b362010-10-14 23:45:03358
359 if (!internal && bp_sp)
360 {
361 m_last_created_breakpoint = bp_sp;
362 }
363
Chris Lattner30fdc8d2010-06-08 16:52:24364 return bp_sp;
365}
366
Johnny Chen86364b42011-09-20 23:28:55367bool
368Target::ProcessIsValid()
369{
370 return (m_process_sp && m_process_sp->IsAlive());
371}
372
Johnny Chenab9ee762011-09-14 00:26:03373// See also WatchpointLocation::SetWatchpointType(uint32_t type) and
374// the OptionGroupWatchpoint::WatchType enum type.
Johnny Chen887062a2011-09-12 23:38:44375WatchpointLocationSP
376Target::CreateWatchpointLocation(lldb::addr_t addr, size_t size, uint32_t type)
377{
Johnny Chen0c406372011-09-14 20:23:45378 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
379 if (log)
380 log->Printf("Target::%s (addr = 0x%8.8llx size = %zu type = %u)\n",
381 __FUNCTION__, addr, size, type);
382
Johnny Chen887062a2011-09-12 23:38:44383 WatchpointLocationSP wp_loc_sp;
Johnny Chen86364b42011-09-20 23:28:55384 if (!ProcessIsValid())
Johnny Chen2fd89a02011-09-13 18:30:59385 return wp_loc_sp;
Johnny Chen45e541f2011-09-14 22:20:15386 if (addr == LLDB_INVALID_ADDRESS || size == 0)
Johnny Chen887062a2011-09-12 23:38:44387 return wp_loc_sp;
Johnny Chen7313a642011-09-13 01:15:36388
Johnny Chenab9ee762011-09-14 00:26:03389 // Currently we only support one watchpoint location per address, with total
390 // number of watchpoint locations limited by the hardware which the inferior
391 // is running on.
Johnny Chen3c532582011-09-13 23:29:31392 WatchpointLocationSP matched_sp = m_watchpoint_location_list.FindByAddress(addr);
393 if (matched_sp)
394 {
Johnny Chen0c406372011-09-14 20:23:45395 size_t old_size = matched_sp->GetByteSize();
Johnny Chen3c532582011-09-13 23:29:31396 uint32_t old_type =
Johnny Chen0c406372011-09-14 20:23:45397 (matched_sp->WatchpointRead() ? LLDB_WATCH_TYPE_READ : 0) |
398 (matched_sp->WatchpointWrite() ? LLDB_WATCH_TYPE_WRITE : 0);
Johnny Chen45e541f2011-09-14 22:20:15399 // Return the existing watchpoint location if both size and type match.
400 if (size == old_size && type == old_type) {
401 wp_loc_sp = matched_sp;
402 wp_loc_sp->SetEnabled(false);
403 } else {
404 // Nil the matched watchpoint location; we will be creating a new one.
405 m_process_sp->DisableWatchpoint(matched_sp.get());
406 m_watchpoint_location_list.Remove(matched_sp->GetID());
407 }
Johnny Chen3c532582011-09-13 23:29:31408 }
409
Johnny Chen45e541f2011-09-14 22:20:15410 if (!wp_loc_sp) {
411 WatchpointLocation *new_loc = new WatchpointLocation(addr, size);
412 if (!new_loc) {
413 printf("WatchpointLocation ctor failed, out of memory?\n");
414 return wp_loc_sp;
415 }
416 new_loc->SetWatchpointType(type);
417 wp_loc_sp.reset(new_loc);
418 m_watchpoint_location_list.Add(wp_loc_sp);
419 }
Johnny Chen0c406372011-09-14 20:23:45420
Johnny Chen0c406372011-09-14 20:23:45421 Error rc = m_process_sp->EnableWatchpoint(wp_loc_sp.get());
Johnny Chen0c406372011-09-14 20:23:45422 if (log)
423 log->Printf("Target::%s (creation of watchpoint %s with id = %u)\n",
424 __FUNCTION__,
425 rc.Success() ? "succeeded" : "failed",
426 wp_loc_sp->GetID());
427
Johnny Chen45e541f2011-09-14 22:20:15428 if (rc.Fail()) wp_loc_sp.reset();
Johnny Chen7313a642011-09-13 01:15:36429 return wp_loc_sp;
Johnny Chen887062a2011-09-12 23:38:44430}
431
Chris Lattner30fdc8d2010-06-08 16:52:24432void
433Target::RemoveAllBreakpoints (bool internal_also)
434{
Greg Clayton2d4edfb2010-11-06 01:53:30435 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24436 if (log)
437 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
438
Greg Clayton9fed0d82010-07-23 23:33:17439 m_breakpoint_list.RemoveAll (true);
Chris Lattner30fdc8d2010-06-08 16:52:24440 if (internal_also)
Greg Clayton9fed0d82010-07-23 23:33:17441 m_internal_breakpoint_list.RemoveAll (false);
Jim Ingham36f3b362010-10-14 23:45:03442
443 m_last_created_breakpoint.reset();
Chris Lattner30fdc8d2010-06-08 16:52:24444}
445
446void
447Target::DisableAllBreakpoints (bool internal_also)
448{
Greg Clayton2d4edfb2010-11-06 01:53:30449 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24450 if (log)
451 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
452
453 m_breakpoint_list.SetEnabledAll (false);
454 if (internal_also)
455 m_internal_breakpoint_list.SetEnabledAll (false);
456}
457
458void
459Target::EnableAllBreakpoints (bool internal_also)
460{
Greg Clayton2d4edfb2010-11-06 01:53:30461 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24462 if (log)
463 log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no");
464
465 m_breakpoint_list.SetEnabledAll (true);
466 if (internal_also)
467 m_internal_breakpoint_list.SetEnabledAll (true);
468}
469
470bool
471Target::RemoveBreakpointByID (break_id_t break_id)
472{
Greg Clayton2d4edfb2010-11-06 01:53:30473 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24474 if (log)
475 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
476
477 if (DisableBreakpointByID (break_id))
478 {
479 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
Greg Clayton9fed0d82010-07-23 23:33:17480 m_internal_breakpoint_list.Remove(break_id, false);
Chris Lattner30fdc8d2010-06-08 16:52:24481 else
Jim Ingham36f3b362010-10-14 23:45:03482 {
Greg Claytonaa1c5872011-01-24 23:35:47483 if (m_last_created_breakpoint)
484 {
485 if (m_last_created_breakpoint->GetID() == break_id)
486 m_last_created_breakpoint.reset();
487 }
Greg Clayton9fed0d82010-07-23 23:33:17488 m_breakpoint_list.Remove(break_id, true);
Jim Ingham36f3b362010-10-14 23:45:03489 }
Chris Lattner30fdc8d2010-06-08 16:52:24490 return true;
491 }
492 return false;
493}
494
495bool
496Target::DisableBreakpointByID (break_id_t break_id)
497{
Greg Clayton2d4edfb2010-11-06 01:53:30498 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24499 if (log)
500 log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
501
502 BreakpointSP bp_sp;
503
504 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
505 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
506 else
507 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
508 if (bp_sp)
509 {
510 bp_sp->SetEnabled (false);
511 return true;
512 }
513 return false;
514}
515
516bool
517Target::EnableBreakpointByID (break_id_t break_id)
518{
Greg Clayton2d4edfb2010-11-06 01:53:30519 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS));
Chris Lattner30fdc8d2010-06-08 16:52:24520 if (log)
521 log->Printf ("Target::%s (break_id = %i, internal = %s)\n",
522 __FUNCTION__,
523 break_id,
524 LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no");
525
526 BreakpointSP bp_sp;
527
528 if (LLDB_BREAK_ID_IS_INTERNAL (break_id))
529 bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id);
530 else
531 bp_sp = m_breakpoint_list.FindBreakpointByID (break_id);
532
533 if (bp_sp)
534 {
535 bp_sp->SetEnabled (true);
536 return true;
537 }
538 return false;
539}
540
Johnny Chen86364b42011-09-20 23:28:55541// Assumption: caller holds the list mutex lock for m_watchpoint_location_list.
542bool
543Target::RemoveAllWatchpointLocations ()
544{
545 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
546 if (log)
547 log->Printf ("Target::%s\n", __FUNCTION__);
548
549 if (!ProcessIsValid())
550 return false;
551
552 size_t num_watchpoints = m_watchpoint_location_list.GetSize();
553 for (size_t i = 0; i < num_watchpoints; ++i)
554 {
555 WatchpointLocationSP wp_loc_sp = m_watchpoint_location_list.GetByIndex(i);
556 if (!wp_loc_sp)
557 return false;
558
559 Error rc = m_process_sp->DisableWatchpoint(wp_loc_sp.get());
560 if (rc.Fail())
561 return false;
562 }
563 m_watchpoint_location_list.RemoveAll ();
564 return true; // Success!
565}
566
567// Assumption: caller holds the list mutex lock for m_watchpoint_location_list.
568bool
569Target::DisableAllWatchpointLocations ()
570{
571 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
572 if (log)
573 log->Printf ("Target::%s\n", __FUNCTION__);
574
575 if (!ProcessIsValid())
576 return false;
577
578 size_t num_watchpoints = m_watchpoint_location_list.GetSize();
579 for (size_t i = 0; i < num_watchpoints; ++i)
580 {
581 WatchpointLocationSP wp_loc_sp = m_watchpoint_location_list.GetByIndex(i);
582 if (!wp_loc_sp)
583 return false;
584
585 Error rc = m_process_sp->DisableWatchpoint(wp_loc_sp.get());
586 if (rc.Fail())
587 return false;
588 }
Johnny Chen86364b42011-09-20 23:28:55589 return true; // Success!
590}
591
592// Assumption: caller holds the list mutex lock for m_watchpoint_location_list.
593bool
594Target::EnableAllWatchpointLocations ()
595{
596 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
597 if (log)
598 log->Printf ("Target::%s\n", __FUNCTION__);
599
600 if (!ProcessIsValid())
601 return false;
602
603 size_t num_watchpoints = m_watchpoint_location_list.GetSize();
604 for (size_t i = 0; i < num_watchpoints; ++i)
605 {
606 WatchpointLocationSP wp_loc_sp = m_watchpoint_location_list.GetByIndex(i);
607 if (!wp_loc_sp)
608 return false;
609
610 Error rc = m_process_sp->EnableWatchpoint(wp_loc_sp.get());
611 if (rc.Fail())
612 return false;
613 }
Johnny Chen86364b42011-09-20 23:28:55614 return true; // Success!
615}
616
617// Assumption: caller holds the list mutex lock for m_watchpoint_location_list.
618bool
619Target::DisableWatchpointLocationByID (lldb::watch_id_t watch_id)
620{
621 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
622 if (log)
623 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
624
625 if (!ProcessIsValid())
626 return false;
627
628 WatchpointLocationSP wp_loc_sp = m_watchpoint_location_list.FindByID (watch_id);
629 if (wp_loc_sp)
630 {
631 Error rc = m_process_sp->DisableWatchpoint(wp_loc_sp.get());
Johnny Chenf04ee932011-09-22 18:04:58632 if (rc.Success())
633 return true;
Johnny Chen86364b42011-09-20 23:28:55634
Johnny Chenf04ee932011-09-22 18:04:58635 // Else, fallthrough.
Johnny Chen86364b42011-09-20 23:28:55636 }
637 return false;
638}
639
640// Assumption: caller holds the list mutex lock for m_watchpoint_location_list.
641bool
642Target::EnableWatchpointLocationByID (lldb::watch_id_t watch_id)
643{
644 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
645 if (log)
646 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
647
648 if (!ProcessIsValid())
649 return false;
650
651 WatchpointLocationSP wp_loc_sp = m_watchpoint_location_list.FindByID (watch_id);
652 if (wp_loc_sp)
653 {
654 Error rc = m_process_sp->EnableWatchpoint(wp_loc_sp.get());
Johnny Chenf04ee932011-09-22 18:04:58655 if (rc.Success())
656 return true;
Johnny Chen86364b42011-09-20 23:28:55657
Johnny Chenf04ee932011-09-22 18:04:58658 // Else, fallthrough.
Johnny Chen86364b42011-09-20 23:28:55659 }
660 return false;
661}
662
663// Assumption: caller holds the list mutex lock for m_watchpoint_location_list.
664bool
665Target::RemoveWatchpointLocationByID (lldb::watch_id_t watch_id)
666{
667 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS));
668 if (log)
669 log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
670
671 if (DisableWatchpointLocationByID (watch_id))
672 {
673 m_watchpoint_location_list.Remove(watch_id);
674 return true;
675 }
676 return false;
677}
678
Chris Lattner30fdc8d2010-06-08 16:52:24679ModuleSP
680Target::GetExecutableModule ()
681{
Greg Claytonaa149cb2011-08-11 02:48:45682 return m_images.GetModuleAtIndex(0);
683}
684
685Module*
686Target::GetExecutableModulePointer ()
687{
688 return m_images.GetModulePointerAtIndex(0);
Chris Lattner30fdc8d2010-06-08 16:52:24689}
690
691void
692Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files)
693{
694 m_images.Clear();
695 m_scratch_ast_context_ap.reset();
696
697 if (executable_sp.get())
698 {
699 Timer scoped_timer (__PRETTY_FUNCTION__,
700 "Target::SetExecutableModule (executable = '%s/%s')",
701 executable_sp->GetFileSpec().GetDirectory().AsCString(),
702 executable_sp->GetFileSpec().GetFilename().AsCString());
703
704 m_images.Append(executable_sp); // The first image is our exectuable file
705
Jim Ingham5aee1622010-08-09 23:31:02706 // 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:51707 if (!m_arch.IsValid())
708 m_arch = executable_sp->GetArchitecture();
Jim Ingham5aee1622010-08-09 23:31:02709
Chris Lattner30fdc8d2010-06-08 16:52:24710 FileSpecList dependent_files;
Greg Claytone996fd32011-03-08 22:40:15711 ObjectFile *executable_objfile = executable_sp->GetObjectFile();
Jim Inghamb7f6b2f2011-09-08 22:13:49712 // Let's find the file & line for main and set the default source file from there.
713 if (!m_source_manager.DefaultFileAndLineSet())
714 {
715 SymbolContextList sc_list;
716 uint32_t num_matches;
717 ConstString main_name("main");
718 bool symbols_okay = false; // Force it to be a debug symbol.
719 bool append = false;
720 num_matches = executable_sp->FindFunctions (main_name, eFunctionNameTypeBase, symbols_okay, append, sc_list);
721 for (uint32_t idx = 0; idx < num_matches; idx++)
722 {
723 SymbolContext sc;
724 sc_list.GetContextAtIndex(idx, sc);
725 if (sc.line_entry.file)
726 {
727 m_source_manager.SetDefaultFileAndLine(sc.line_entry.file, sc.line_entry.line);
728 break;
729 }
730 }
731 }
Chris Lattner30fdc8d2010-06-08 16:52:24732
733 if (executable_objfile)
734 {
735 executable_objfile->GetDependentModules(dependent_files);
736 for (uint32_t i=0; i<dependent_files.GetSize(); i++)
737 {
Greg Claytonded470d2011-03-19 01:12:21738 FileSpec dependent_file_spec (dependent_files.GetFileSpecPointerAtIndex(i));
739 FileSpec platform_dependent_file_spec;
740 if (m_platform_sp)
Greg Claytond314e812011-03-23 00:09:55741 m_platform_sp->GetFile (dependent_file_spec, NULL, platform_dependent_file_spec);
Greg Claytonded470d2011-03-19 01:12:21742 else
743 platform_dependent_file_spec = dependent_file_spec;
744
745 ModuleSP image_module_sp(GetSharedModule (platform_dependent_file_spec,
Greg Clayton32e0a752011-03-30 18:16:51746 m_arch));
Chris Lattner30fdc8d2010-06-08 16:52:24747 if (image_module_sp.get())
748 {
Chris Lattner30fdc8d2010-06-08 16:52:24749 ObjectFile *objfile = image_module_sp->GetObjectFile();
750 if (objfile)
751 objfile->GetDependentModules(dependent_files);
752 }
753 }
754 }
755
Chris Lattner30fdc8d2010-06-08 16:52:24756 }
Caroline Tice1559a462010-09-27 00:30:10757
758 UpdateInstanceName();
Chris Lattner30fdc8d2010-06-08 16:52:24759}
760
761
Jim Ingham5aee1622010-08-09 23:31:02762bool
763Target::SetArchitecture (const ArchSpec &arch_spec)
764{
Greg Clayton32e0a752011-03-30 18:16:51765 if (m_arch == arch_spec)
Jim Ingham5aee1622010-08-09 23:31:02766 {
767 // If we're setting the architecture to our current architecture, we
768 // don't need to do anything.
769 return true;
770 }
Greg Clayton32e0a752011-03-30 18:16:51771 else if (!m_arch.IsValid())
Jim Ingham5aee1622010-08-09 23:31:02772 {
773 // If we haven't got a valid arch spec, then we just need to set it.
Greg Clayton32e0a752011-03-30 18:16:51774 m_arch = arch_spec;
Jim Ingham5aee1622010-08-09 23:31:02775 return true;
776 }
777 else
778 {
779 // If we have an executable file, try to reset the executable to the desired architecture
Greg Clayton32e0a752011-03-30 18:16:51780 m_arch = arch_spec;
Jim Ingham5aee1622010-08-09 23:31:02781 ModuleSP executable_sp = GetExecutableModule ();
782 m_images.Clear();
783 m_scratch_ast_context_ap.reset();
Jim Ingham5aee1622010-08-09 23:31:02784 // Need to do something about unsetting breakpoints.
785
786 if (executable_sp)
787 {
788 FileSpec exec_file_spec = executable_sp->GetFileSpec();
789 Error error = ModuleList::GetSharedModule(exec_file_spec,
790 arch_spec,
791 NULL,
792 NULL,
793 0,
794 executable_sp,
795 NULL,
796 NULL);
797
798 if (!error.Fail() && executable_sp)
799 {
800 SetExecutableModule (executable_sp, true);
801 return true;
802 }
803 else
804 {
805 return false;
806 }
807 }
808 else
809 {
810 return false;
811 }
812 }
813}
Chris Lattner30fdc8d2010-06-08 16:52:24814
Chris Lattner30fdc8d2010-06-08 16:52:24815void
816Target::ModuleAdded (ModuleSP &module_sp)
817{
818 // A module is being added to this target for the first time
819 ModuleList module_list;
820 module_list.Append(module_sp);
821 ModulesDidLoad (module_list);
822}
823
824void
825Target::ModuleUpdated (ModuleSP &old_module_sp, ModuleSP &new_module_sp)
826{
Jim Inghame716ae02011-08-03 01:00:06827 // A module is replacing an already added module
Chris Lattner30fdc8d2010-06-08 16:52:24828 ModuleList module_list;
829 module_list.Append (old_module_sp);
830 ModulesDidUnload (module_list);
831 module_list.Clear ();
832 module_list.Append (new_module_sp);
833 ModulesDidLoad (module_list);
834}
835
836void
837Target::ModulesDidLoad (ModuleList &module_list)
838{
839 m_breakpoint_list.UpdateBreakpoints (module_list, true);
840 // TODO: make event data that packages up the module_list
841 BroadcastEvent (eBroadcastBitModulesLoaded, NULL);
842}
843
844void
845Target::ModulesDidUnload (ModuleList &module_list)
846{
847 m_breakpoint_list.UpdateBreakpoints (module_list, false);
Greg Claytona4d78302010-12-06 23:51:26848
849 // Remove the images from the target image list
850 m_images.Remove(module_list);
851
Chris Lattner30fdc8d2010-06-08 16:52:24852 // TODO: make event data that packages up the module_list
853 BroadcastEvent (eBroadcastBitModulesUnloaded, NULL);
854}
855
856size_t
Greg Claytondb598232011-01-07 01:57:07857Target::ReadMemoryFromFileCache (const Address& addr, void *dst, size_t dst_len, Error &error)
858{
859 const Section *section = addr.GetSection();
860 if (section && section->GetModule())
861 {
862 ObjectFile *objfile = section->GetModule()->GetObjectFile();
863 if (objfile)
864 {
865 size_t bytes_read = section->ReadSectionDataFromObjectFile (objfile,
866 addr.GetOffset(),
867 dst,
868 dst_len);
869 if (bytes_read > 0)
870 return bytes_read;
871 else
872 error.SetErrorStringWithFormat("error reading data from section %s", section->GetName().GetCString());
873 }
874 else
875 {
876 error.SetErrorString("address isn't from a object file");
877 }
878 }
879 else
880 {
881 error.SetErrorString("address doesn't contain a section that points to a section in a object file");
882 }
883 return 0;
884}
885
886size_t
Enrico Granata9128ee2f2011-09-06 19:20:51887Target::ReadMemory (const Address& addr,
888 bool prefer_file_cache,
889 void *dst,
890 size_t dst_len,
891 Error &error,
892 lldb::addr_t *load_addr_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24893{
Chris Lattner30fdc8d2010-06-08 16:52:24894 error.Clear();
Greg Claytondb598232011-01-07 01:57:07895
Enrico Granata9128ee2f2011-09-06 19:20:51896 // if we end up reading this from process memory, we will fill this
897 // with the actual load address
898 if (load_addr_ptr)
899 *load_addr_ptr = LLDB_INVALID_ADDRESS;
900
Greg Claytondb598232011-01-07 01:57:07901 size_t bytes_read = 0;
Greg Claytonc749eb82011-07-11 05:12:02902
903 addr_t load_addr = LLDB_INVALID_ADDRESS;
904 addr_t file_addr = LLDB_INVALID_ADDRESS;
Greg Clayton357132e2011-03-26 19:14:58905 Address resolved_addr;
906 if (!addr.IsSectionOffset())
Greg Claytondda4f7b2010-06-30 23:03:03907 {
Greg Claytond16e1e52011-07-12 17:06:17908 if (m_section_load_list.IsEmpty())
Greg Claytonc749eb82011-07-11 05:12:02909 {
Greg Claytond16e1e52011-07-12 17:06:17910 // No sections are loaded, so we must assume we are not running
911 // yet and anything we are given is a file address.
912 file_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the file address
913 m_images.ResolveFileAddress (file_addr, resolved_addr);
Greg Claytonc749eb82011-07-11 05:12:02914 }
Greg Claytondda4f7b2010-06-30 23:03:03915 else
Greg Claytonc749eb82011-07-11 05:12:02916 {
Greg Claytond16e1e52011-07-12 17:06:17917 // We have at least one section loaded. This can be becuase
918 // we have manually loaded some sections with "target modules load ..."
919 // or because we have have a live process that has sections loaded
920 // through the dynamic loader
921 load_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the load address
922 m_section_load_list.ResolveLoadAddress (load_addr, resolved_addr);
Greg Claytonc749eb82011-07-11 05:12:02923 }
Greg Claytondda4f7b2010-06-30 23:03:03924 }
Greg Clayton357132e2011-03-26 19:14:58925 if (!resolved_addr.IsValid())
926 resolved_addr = addr;
Greg Claytondda4f7b2010-06-30 23:03:03927
Greg Claytonc749eb82011-07-11 05:12:02928
Greg Claytondb598232011-01-07 01:57:07929 if (prefer_file_cache)
930 {
931 bytes_read = ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
932 if (bytes_read > 0)
933 return bytes_read;
934 }
Greg Claytondda4f7b2010-06-30 23:03:03935
Johnny Chen86364b42011-09-20 23:28:55936 if (ProcessIsValid())
Greg Claytondda4f7b2010-06-30 23:03:03937 {
Greg Claytonc749eb82011-07-11 05:12:02938 if (load_addr == LLDB_INVALID_ADDRESS)
939 load_addr = resolved_addr.GetLoadAddress (this);
940
Greg Claytondda4f7b2010-06-30 23:03:03941 if (load_addr == LLDB_INVALID_ADDRESS)
942 {
943 if (resolved_addr.GetModule() && resolved_addr.GetModule()->GetFileSpec())
944 error.SetErrorStringWithFormat("%s[0x%llx] can't be resolved, %s in not currently loaded.\n",
945 resolved_addr.GetModule()->GetFileSpec().GetFilename().AsCString(),
Jason Molenda7e589a62011-09-20 00:26:08946 resolved_addr.GetFileAddress(),
947 resolved_addr.GetModule()->GetFileSpec().GetFilename().AsCString());
Greg Claytondda4f7b2010-06-30 23:03:03948 else
949 error.SetErrorStringWithFormat("0x%llx can't be resolved.\n", resolved_addr.GetFileAddress());
950 }
951 else
952 {
Greg Claytondb598232011-01-07 01:57:07953 bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error);
Chris Lattner30fdc8d2010-06-08 16:52:24954 if (bytes_read != dst_len)
955 {
956 if (error.Success())
957 {
958 if (bytes_read == 0)
Greg Claytondda4f7b2010-06-30 23:03:03959 error.SetErrorStringWithFormat("Read memory from 0x%llx failed.\n", load_addr);
Chris Lattner30fdc8d2010-06-08 16:52:24960 else
Greg Claytondda4f7b2010-06-30 23:03:03961 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:24962 }
963 }
Greg Claytondda4f7b2010-06-30 23:03:03964 if (bytes_read)
Enrico Granata9128ee2f2011-09-06 19:20:51965 {
966 if (load_addr_ptr)
967 *load_addr_ptr = load_addr;
Greg Claytondda4f7b2010-06-30 23:03:03968 return bytes_read;
Enrico Granata9128ee2f2011-09-06 19:20:51969 }
Greg Claytondda4f7b2010-06-30 23:03:03970 // If the address is not section offset we have an address that
971 // doesn't resolve to any address in any currently loaded shared
972 // libaries and we failed to read memory so there isn't anything
973 // more we can do. If it is section offset, we might be able to
974 // read cached memory from the object file.
975 if (!resolved_addr.IsSectionOffset())
976 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24977 }
Chris Lattner30fdc8d2010-06-08 16:52:24978 }
Greg Claytondda4f7b2010-06-30 23:03:03979
Greg Claytonc749eb82011-07-11 05:12:02980 if (!prefer_file_cache && resolved_addr.IsSectionOffset())
Greg Claytondda4f7b2010-06-30 23:03:03981 {
Greg Claytondb598232011-01-07 01:57:07982 // If we didn't already try and read from the object file cache, then
983 // try it after failing to read from the process.
984 return ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error);
Greg Claytondda4f7b2010-06-30 23:03:03985 }
986 return 0;
Chris Lattner30fdc8d2010-06-08 16:52:24987}
988
Greg Claytond16e1e52011-07-12 17:06:17989size_t
990Target::ReadScalarIntegerFromMemory (const Address& addr,
991 bool prefer_file_cache,
992 uint32_t byte_size,
993 bool is_signed,
994 Scalar &scalar,
995 Error &error)
996{
997 uint64_t uval;
998
999 if (byte_size <= sizeof(uval))
1000 {
1001 size_t bytes_read = ReadMemory (addr, prefer_file_cache, &uval, byte_size, error);
1002 if (bytes_read == byte_size)
1003 {
1004 DataExtractor data (&uval, sizeof(uval), m_arch.GetByteOrder(), m_arch.GetAddressByteSize());
1005 uint32_t offset = 0;
1006 if (byte_size <= 4)
1007 scalar = data.GetMaxU32 (&offset, byte_size);
1008 else
1009 scalar = data.GetMaxU64 (&offset, byte_size);
1010
1011 if (is_signed)
1012 scalar.SignExtend(byte_size * 8);
1013 return bytes_read;
1014 }
1015 }
1016 else
1017 {
1018 error.SetErrorStringWithFormat ("byte size of %u is too large for integer scalar type", byte_size);
1019 }
1020 return 0;
1021}
1022
1023uint64_t
1024Target::ReadUnsignedIntegerFromMemory (const Address& addr,
1025 bool prefer_file_cache,
1026 size_t integer_byte_size,
1027 uint64_t fail_value,
1028 Error &error)
1029{
1030 Scalar scalar;
1031 if (ReadScalarIntegerFromMemory (addr,
1032 prefer_file_cache,
1033 integer_byte_size,
1034 false,
1035 scalar,
1036 error))
1037 return scalar.ULongLong(fail_value);
1038 return fail_value;
1039}
1040
1041bool
1042Target::ReadPointerFromMemory (const Address& addr,
1043 bool prefer_file_cache,
1044 Error &error,
1045 Address &pointer_addr)
1046{
1047 Scalar scalar;
1048 if (ReadScalarIntegerFromMemory (addr,
1049 prefer_file_cache,
1050 m_arch.GetAddressByteSize(),
1051 false,
1052 scalar,
1053 error))
1054 {
1055 addr_t pointer_vm_addr = scalar.ULongLong(LLDB_INVALID_ADDRESS);
1056 if (pointer_vm_addr != LLDB_INVALID_ADDRESS)
1057 {
1058 if (m_section_load_list.IsEmpty())
1059 {
1060 // No sections are loaded, so we must assume we are not running
1061 // yet and anything we are given is a file address.
1062 m_images.ResolveFileAddress (pointer_vm_addr, pointer_addr);
1063 }
1064 else
1065 {
1066 // We have at least one section loaded. This can be becuase
1067 // we have manually loaded some sections with "target modules load ..."
1068 // or because we have have a live process that has sections loaded
1069 // through the dynamic loader
1070 m_section_load_list.ResolveLoadAddress (pointer_vm_addr, pointer_addr);
1071 }
1072 // We weren't able to resolve the pointer value, so just return
1073 // an address with no section
1074 if (!pointer_addr.IsValid())
1075 pointer_addr.SetOffset (pointer_vm_addr);
1076 return true;
1077
1078 }
1079 }
1080 return false;
1081}
Chris Lattner30fdc8d2010-06-08 16:52:241082
1083ModuleSP
1084Target::GetSharedModule
1085(
1086 const FileSpec& file_spec,
1087 const ArchSpec& arch,
Greg Clayton60830262011-02-04 18:53:101088 const lldb_private::UUID *uuid_ptr,
Chris Lattner30fdc8d2010-06-08 16:52:241089 const ConstString *object_name,
1090 off_t object_offset,
1091 Error *error_ptr
1092)
1093{
1094 // Don't pass in the UUID so we can tell if we have a stale value in our list
1095 ModuleSP old_module_sp; // This will get filled in if we have a new version of the library
1096 bool did_create_module = false;
1097 ModuleSP module_sp;
1098
Chris Lattner30fdc8d2010-06-08 16:52:241099 Error error;
1100
Greg Clayton32e0a752011-03-30 18:16:511101 // If there are image search path entries, try to use them first to acquire a suitable image.
Chris Lattner30fdc8d2010-06-08 16:52:241102 if (m_image_search_paths.GetSize())
1103 {
1104 FileSpec transformed_spec;
1105 if (m_image_search_paths.RemapPath (file_spec.GetDirectory(), transformed_spec.GetDirectory()))
1106 {
1107 transformed_spec.GetFilename() = file_spec.GetFilename();
1108 error = ModuleList::GetSharedModule (transformed_spec, arch, uuid_ptr, object_name, object_offset, module_sp, &old_module_sp, &did_create_module);
1109 }
1110 }
1111
Greg Clayton32e0a752011-03-30 18:16:511112 // The platform is responsible for finding and caching an appropriate
1113 // module in the shared module cache.
1114 if (m_platform_sp)
Chris Lattner30fdc8d2010-06-08 16:52:241115 {
Greg Clayton32e0a752011-03-30 18:16:511116 FileSpec platform_file_spec;
1117 error = m_platform_sp->GetSharedModule (file_spec,
1118 arch,
1119 uuid_ptr,
1120 object_name,
1121 object_offset,
1122 module_sp,
1123 &old_module_sp,
1124 &did_create_module);
1125 }
1126 else
1127 {
1128 error.SetErrorString("no platform is currently set");
Chris Lattner30fdc8d2010-06-08 16:52:241129 }
1130
Greg Clayton32e0a752011-03-30 18:16:511131 // If a module hasn't been found yet, use the unmodified path.
Chris Lattner30fdc8d2010-06-08 16:52:241132 if (module_sp)
1133 {
1134 m_images.Append (module_sp);
1135 if (did_create_module)
1136 {
1137 if (old_module_sp && m_images.GetIndexForModule (old_module_sp.get()) != LLDB_INVALID_INDEX32)
1138 ModuleUpdated(old_module_sp, module_sp);
1139 else
1140 ModuleAdded(module_sp);
1141 }
1142 }
1143 if (error_ptr)
1144 *error_ptr = error;
1145 return module_sp;
1146}
1147
1148
1149Target *
1150Target::CalculateTarget ()
1151{
1152 return this;
1153}
1154
1155Process *
1156Target::CalculateProcess ()
1157{
1158 return NULL;
1159}
1160
1161Thread *
1162Target::CalculateThread ()
1163{
1164 return NULL;
1165}
1166
1167StackFrame *
1168Target::CalculateStackFrame ()
1169{
1170 return NULL;
1171}
1172
1173void
Greg Clayton0603aa92010-10-04 01:05:561174Target::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner30fdc8d2010-06-08 16:52:241175{
Greg Claytonc14ee322011-09-22 04:58:261176 exe_ctx.Clear();
1177 exe_ctx.SetTargetPtr(this);
Chris Lattner30fdc8d2010-06-08 16:52:241178}
1179
1180PathMappingList &
1181Target::GetImageSearchPathList ()
1182{
1183 return m_image_search_paths;
1184}
1185
1186void
1187Target::ImageSearchPathsChanged
1188(
1189 const PathMappingList &path_list,
1190 void *baton
1191)
1192{
1193 Target *target = (Target *)baton;
Greg Claytonaa149cb2011-08-11 02:48:451194 ModuleSP exe_module_sp (target->GetExecutableModule());
1195 if (exe_module_sp)
Chris Lattner30fdc8d2010-06-08 16:52:241196 {
Greg Claytonaa149cb2011-08-11 02:48:451197 target->m_images.Clear();
1198 target->SetExecutableModule (exe_module_sp, true);
Chris Lattner30fdc8d2010-06-08 16:52:241199 }
1200}
1201
1202ClangASTContext *
1203Target::GetScratchClangASTContext()
1204{
Greg Clayton73da2442011-08-03 01:23:551205 // Now see if we know the target triple, and if so, create our scratch AST context:
1206 if (m_scratch_ast_context_ap.get() == NULL && m_arch.IsValid())
1207 m_scratch_ast_context_ap.reset (new ClangASTContext(m_arch.GetTriple().str().c_str()));
Chris Lattner30fdc8d2010-06-08 16:52:241208 return m_scratch_ast_context_ap.get();
1209}
Caroline Ticedaccaa92010-09-20 20:44:431210
Greg Clayton99d0faf2010-11-18 23:32:351211void
Caroline Tice20bd37f2011-03-10 22:14:101212Target::SettingsInitialize ()
Caroline Ticedaccaa92010-09-20 20:44:431213{
Greg Clayton99d0faf2010-11-18 23:32:351214 UserSettingsControllerSP &usc = GetSettingsController();
1215 usc.reset (new SettingsController);
1216 UserSettingsController::InitializeSettingsController (usc,
1217 SettingsController::global_settings_table,
1218 SettingsController::instance_settings_table);
Caroline Tice20bd37f2011-03-10 22:14:101219
1220 // Now call SettingsInitialize() on each 'child' setting of Target
1221 Process::SettingsInitialize ();
Greg Clayton99d0faf2010-11-18 23:32:351222}
Caroline Ticedaccaa92010-09-20 20:44:431223
Greg Clayton99d0faf2010-11-18 23:32:351224void
Caroline Tice20bd37f2011-03-10 22:14:101225Target::SettingsTerminate ()
Greg Clayton99d0faf2010-11-18 23:32:351226{
Caroline Tice20bd37f2011-03-10 22:14:101227
1228 // Must call SettingsTerminate() on each settings 'child' of Target, before terminating Target's Settings.
1229
1230 Process::SettingsTerminate ();
1231
1232 // Now terminate Target Settings.
1233
Greg Clayton99d0faf2010-11-18 23:32:351234 UserSettingsControllerSP &usc = GetSettingsController();
1235 UserSettingsController::FinalizeSettingsController (usc);
1236 usc.reset();
1237}
Caroline Ticedaccaa92010-09-20 20:44:431238
Greg Clayton99d0faf2010-11-18 23:32:351239UserSettingsControllerSP &
1240Target::GetSettingsController ()
1241{
1242 static UserSettingsControllerSP g_settings_controller;
Caroline Ticedaccaa92010-09-20 20:44:431243 return g_settings_controller;
1244}
1245
1246ArchSpec
1247Target::GetDefaultArchitecture ()
1248{
Greg Clayton64195a22011-02-23 00:35:021249 lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController());
1250
1251 if (settings_controller_sp)
1252 return static_cast<Target::SettingsController *>(settings_controller_sp.get())->GetArchitecture ();
1253 return ArchSpec();
Caroline Ticedaccaa92010-09-20 20:44:431254}
1255
1256void
Greg Clayton64195a22011-02-23 00:35:021257Target::SetDefaultArchitecture (const ArchSpec& arch)
Caroline Ticedaccaa92010-09-20 20:44:431258{
Greg Clayton64195a22011-02-23 00:35:021259 lldb::UserSettingsControllerSP settings_controller_sp (GetSettingsController());
1260
1261 if (settings_controller_sp)
1262 static_cast<Target::SettingsController *>(settings_controller_sp.get())->GetArchitecture () = arch;
Caroline Ticedaccaa92010-09-20 20:44:431263}
1264
Greg Clayton0603aa92010-10-04 01:05:561265Target *
1266Target::GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, const SymbolContext *sc_ptr)
1267{
1268 // The target can either exist in the "process" of ExecutionContext, or in
1269 // the "target_sp" member of SymbolContext. This accessor helper function
1270 // will get the target from one of these locations.
1271
1272 Target *target = NULL;
1273 if (sc_ptr != NULL)
1274 target = sc_ptr->target_sp.get();
Greg Claytonc14ee322011-09-22 04:58:261275 if (target == NULL && exe_ctx_ptr)
1276 target = exe_ctx_ptr->GetTargetPtr();
Greg Clayton0603aa92010-10-04 01:05:561277 return target;
1278}
1279
1280
Caroline Tice1559a462010-09-27 00:30:101281void
1282Target::UpdateInstanceName ()
1283{
1284 StreamString sstr;
1285
Greg Claytonaa149cb2011-08-11 02:48:451286 Module *exe_module = GetExecutableModulePointer();
1287 if (exe_module)
Caroline Tice1559a462010-09-27 00:30:101288 {
Greg Clayton307de252010-10-27 02:06:371289 sstr.Printf ("%s_%s",
Greg Claytonaa149cb2011-08-11 02:48:451290 exe_module->GetFileSpec().GetFilename().AsCString(),
1291 exe_module->GetArchitecture().GetArchitectureName());
1292 GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(), sstr.GetData());
Caroline Tice1559a462010-09-27 00:30:101293 }
1294}
1295
Sean Callanan322f5292010-10-29 00:29:031296const char *
1297Target::GetExpressionPrefixContentsAsCString ()
1298{
Greg Clayton7e14f912011-04-23 02:04:551299 if (m_expr_prefix_contents_sp)
1300 return (const char *)m_expr_prefix_contents_sp->GetBytes();
1301 return NULL;
Sean Callanan322f5292010-10-29 00:29:031302}
1303
Greg Clayton8b2fe6d2010-12-14 02:59:591304ExecutionResults
1305Target::EvaluateExpression
1306(
1307 const char *expr_cstr,
1308 StackFrame *frame,
Sean Callanan3bfdaa22011-09-15 02:13:071309 lldb_private::ExecutionPolicy execution_policy,
Greg Clayton8b2fe6d2010-12-14 02:59:591310 bool unwind_on_error,
Sean Callanan92adcac2011-01-13 08:53:351311 bool keep_in_memory,
Jim Ingham2837b762011-05-04 03:43:181312 lldb::DynamicValueType use_dynamic,
Greg Clayton8b2fe6d2010-12-14 02:59:591313 lldb::ValueObjectSP &result_valobj_sp
1314)
1315{
1316 ExecutionResults execution_results = eExecutionSetupError;
1317
1318 result_valobj_sp.reset();
Jim Ingham6026ca32011-05-12 02:06:141319
1320 // We shouldn't run stop hooks in expressions.
1321 // Be sure to reset this if you return anywhere within this function.
1322 bool old_suppress_value = m_suppress_stop_hooks;
1323 m_suppress_stop_hooks = true;
Greg Clayton8b2fe6d2010-12-14 02:59:591324
1325 ExecutionContext exe_ctx;
1326 if (frame)
1327 {
1328 frame->CalculateExecutionContext(exe_ctx);
Greg Clayton54979cd2010-12-15 05:08:081329 Error error;
Greg Clayton6d5e68e2011-01-20 19:27:181330 const uint32_t expr_path_options = StackFrame::eExpressionPathOptionCheckPtrVsMember |
Enrico Granata27b625e2011-08-09 01:04:561331 StackFrame::eExpressionPathOptionsNoFragileObjcIvar |
1332 StackFrame::eExpressionPathOptionsNoSyntheticChildren;
Jim Ingham2837b762011-05-04 03:43:181333 lldb::VariableSP var_sp;
1334 result_valobj_sp = frame->GetValueForVariableExpressionPath (expr_cstr,
1335 use_dynamic,
1336 expr_path_options,
1337 var_sp,
1338 error);
Greg Clayton8b2fe6d2010-12-14 02:59:591339 }
1340 else if (m_process_sp)
1341 {
1342 m_process_sp->CalculateExecutionContext(exe_ctx);
1343 }
1344 else
1345 {
1346 CalculateExecutionContext(exe_ctx);
1347 }
1348
1349 if (result_valobj_sp)
1350 {
1351 execution_results = eExecutionCompleted;
1352 // We got a result from the frame variable expression path above...
1353 ConstString persistent_variable_name (m_persistent_variables.GetNextPersistentVariableName());
1354
1355 lldb::ValueObjectSP const_valobj_sp;
1356
1357 // Check in case our value is already a constant value
1358 if (result_valobj_sp->GetIsConstant())
1359 {
1360 const_valobj_sp = result_valobj_sp;
1361 const_valobj_sp->SetName (persistent_variable_name);
1362 }
1363 else
Jim Ingham78a685a2011-04-16 00:01:131364 {
Jim Ingham2837b762011-05-04 03:43:181365 if (use_dynamic != lldb::eNoDynamicValues)
Jim Ingham78a685a2011-04-16 00:01:131366 {
Jim Ingham2837b762011-05-04 03:43:181367 ValueObjectSP dynamic_sp = result_valobj_sp->GetDynamicValue(use_dynamic);
Jim Ingham78a685a2011-04-16 00:01:131368 if (dynamic_sp)
1369 result_valobj_sp = dynamic_sp;
1370 }
1371
Jim Ingham6035b672011-03-31 00:19:251372 const_valobj_sp = result_valobj_sp->CreateConstantValue (persistent_variable_name);
Jim Ingham78a685a2011-04-16 00:01:131373 }
Greg Clayton8b2fe6d2010-12-14 02:59:591374
Sean Callanan92adcac2011-01-13 08:53:351375 lldb::ValueObjectSP live_valobj_sp = result_valobj_sp;
1376
Greg Clayton8b2fe6d2010-12-14 02:59:591377 result_valobj_sp = const_valobj_sp;
1378
Sean Callanan92adcac2011-01-13 08:53:351379 ClangExpressionVariableSP clang_expr_variable_sp(m_persistent_variables.CreatePersistentVariable(result_valobj_sp));
1380 assert (clang_expr_variable_sp.get());
1381
1382 // Set flags and live data as appropriate
1383
1384 const Value &result_value = live_valobj_sp->GetValue();
1385
1386 switch (result_value.GetValueType())
1387 {
1388 case Value::eValueTypeHostAddress:
1389 case Value::eValueTypeFileAddress:
1390 // we don't do anything with these for now
1391 break;
1392 case Value::eValueTypeScalar:
1393 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsLLDBAllocated;
1394 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVNeedsAllocation;
1395 break;
1396 case Value::eValueTypeLoadAddress:
1397 clang_expr_variable_sp->m_live_sp = live_valobj_sp;
1398 clang_expr_variable_sp->m_flags |= ClangExpressionVariable::EVIsProgramReference;
1399 break;
1400 }
Greg Clayton8b2fe6d2010-12-14 02:59:591401 }
1402 else
1403 {
1404 // Make sure we aren't just trying to see the value of a persistent
1405 // variable (something like "$0")
Greg Clayton3e06bd92011-01-09 21:07:351406 lldb::ClangExpressionVariableSP persistent_var_sp;
1407 // Only check for persistent variables the expression starts with a '$'
1408 if (expr_cstr[0] == '$')
1409 persistent_var_sp = m_persistent_variables.GetVariable (expr_cstr);
1410
Greg Clayton8b2fe6d2010-12-14 02:59:591411 if (persistent_var_sp)
1412 {
1413 result_valobj_sp = persistent_var_sp->GetValueObject ();
1414 execution_results = eExecutionCompleted;
1415 }
1416 else
1417 {
1418 const char *prefix = GetExpressionPrefixContentsAsCString();
Sean Callanan3bfdaa22011-09-15 02:13:071419
Greg Clayton8b2fe6d2010-12-14 02:59:591420 execution_results = ClangUserExpression::Evaluate (exe_ctx,
Sean Callanan3bfdaa22011-09-15 02:13:071421 execution_policy,
Sean Callanan92adcac2011-01-13 08:53:351422 unwind_on_error,
Greg Clayton8b2fe6d2010-12-14 02:59:591423 expr_cstr,
1424 prefix,
1425 result_valobj_sp);
1426 }
1427 }
Jim Ingham6026ca32011-05-12 02:06:141428
1429 m_suppress_stop_hooks = old_suppress_value;
1430
Greg Clayton8b2fe6d2010-12-14 02:59:591431 return execution_results;
1432}
1433
Greg Claytonf3ef3d22011-05-22 22:46:531434lldb::addr_t
1435Target::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
1436{
1437 addr_t code_addr = load_addr;
1438 switch (m_arch.GetMachine())
1439 {
1440 case llvm::Triple::arm:
1441 case llvm::Triple::thumb:
1442 switch (addr_class)
1443 {
1444 case eAddressClassData:
1445 case eAddressClassDebug:
1446 return LLDB_INVALID_ADDRESS;
1447
1448 case eAddressClassUnknown:
1449 case eAddressClassInvalid:
1450 case eAddressClassCode:
1451 case eAddressClassCodeAlternateISA:
1452 case eAddressClassRuntime:
1453 // Check if bit zero it no set?
1454 if ((code_addr & 1ull) == 0)
1455 {
1456 // Bit zero isn't set, check if the address is a multiple of 2?
1457 if (code_addr & 2ull)
1458 {
1459 // The address is a multiple of 2 so it must be thumb, set bit zero
1460 code_addr |= 1ull;
1461 }
1462 else if (addr_class == eAddressClassCodeAlternateISA)
1463 {
1464 // We checked the address and the address claims to be the alternate ISA
1465 // which means thumb, so set bit zero.
1466 code_addr |= 1ull;
1467 }
1468 }
1469 break;
1470 }
1471 break;
1472
1473 default:
1474 break;
1475 }
1476 return code_addr;
1477}
1478
1479lldb::addr_t
1480Target::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const
1481{
1482 addr_t opcode_addr = load_addr;
1483 switch (m_arch.GetMachine())
1484 {
1485 case llvm::Triple::arm:
1486 case llvm::Triple::thumb:
1487 switch (addr_class)
1488 {
1489 case eAddressClassData:
1490 case eAddressClassDebug:
1491 return LLDB_INVALID_ADDRESS;
1492
1493 case eAddressClassInvalid:
1494 case eAddressClassUnknown:
1495 case eAddressClassCode:
1496 case eAddressClassCodeAlternateISA:
1497 case eAddressClassRuntime:
1498 opcode_addr &= ~(1ull);
1499 break;
1500 }
1501 break;
1502
1503 default:
1504 break;
1505 }
1506 return opcode_addr;
1507}
1508
Jim Ingham9575d842011-03-11 03:53:591509lldb::user_id_t
1510Target::AddStopHook (Target::StopHookSP &new_hook_sp)
1511{
1512 lldb::user_id_t new_uid = ++m_stop_hook_next_id;
1513 new_hook_sp.reset (new StopHook(GetSP(), new_uid));
1514 m_stop_hooks[new_uid] = new_hook_sp;
1515 return new_uid;
1516}
1517
1518bool
1519Target::RemoveStopHookByID (lldb::user_id_t user_id)
1520{
1521 size_t num_removed;
1522 num_removed = m_stop_hooks.erase (user_id);
1523 if (num_removed == 0)
1524 return false;
1525 else
1526 return true;
1527}
1528
1529void
1530Target::RemoveAllStopHooks ()
1531{
1532 m_stop_hooks.clear();
1533}
1534
1535Target::StopHookSP
1536Target::GetStopHookByID (lldb::user_id_t user_id)
1537{
1538 StopHookSP found_hook;
1539
1540 StopHookCollection::iterator specified_hook_iter;
1541 specified_hook_iter = m_stop_hooks.find (user_id);
1542 if (specified_hook_iter != m_stop_hooks.end())
1543 found_hook = (*specified_hook_iter).second;
1544 return found_hook;
1545}
1546
1547bool
1548Target::SetStopHookActiveStateByID (lldb::user_id_t user_id, bool active_state)
1549{
1550 StopHookCollection::iterator specified_hook_iter;
1551 specified_hook_iter = m_stop_hooks.find (user_id);
1552 if (specified_hook_iter == m_stop_hooks.end())
1553 return false;
1554
1555 (*specified_hook_iter).second->SetIsActive (active_state);
1556 return true;
1557}
1558
1559void
1560Target::SetAllStopHooksActiveState (bool active_state)
1561{
1562 StopHookCollection::iterator pos, end = m_stop_hooks.end();
1563 for (pos = m_stop_hooks.begin(); pos != end; pos++)
1564 {
1565 (*pos).second->SetIsActive (active_state);
1566 }
1567}
1568
1569void
1570Target::RunStopHooks ()
1571{
Jim Ingham6026ca32011-05-12 02:06:141572 if (m_suppress_stop_hooks)
1573 return;
1574
Jim Ingham9575d842011-03-11 03:53:591575 if (!m_process_sp)
1576 return;
1577
1578 if (m_stop_hooks.empty())
1579 return;
1580
1581 StopHookCollection::iterator pos, end = m_stop_hooks.end();
1582
1583 // If there aren't any active stop hooks, don't bother either:
1584 bool any_active_hooks = false;
1585 for (pos = m_stop_hooks.begin(); pos != end; pos++)
1586 {
1587 if ((*pos).second->IsActive())
1588 {
1589 any_active_hooks = true;
1590 break;
1591 }
1592 }
1593 if (!any_active_hooks)
1594 return;
1595
1596 CommandReturnObject result;
1597
1598 std::vector<ExecutionContext> exc_ctx_with_reasons;
1599 std::vector<SymbolContext> sym_ctx_with_reasons;
1600
1601 ThreadList &cur_threadlist = m_process_sp->GetThreadList();
1602 size_t num_threads = cur_threadlist.GetSize();
1603 for (size_t i = 0; i < num_threads; i++)
1604 {
1605 lldb::ThreadSP cur_thread_sp = cur_threadlist.GetThreadAtIndex (i);
1606 if (cur_thread_sp->ThreadStoppedForAReason())
1607 {
1608 lldb::StackFrameSP cur_frame_sp = cur_thread_sp->GetStackFrameAtIndex(0);
1609 exc_ctx_with_reasons.push_back(ExecutionContext(m_process_sp.get(), cur_thread_sp.get(), cur_frame_sp.get()));
1610 sym_ctx_with_reasons.push_back(cur_frame_sp->GetSymbolContext(eSymbolContextEverything));
1611 }
1612 }
1613
1614 // If no threads stopped for a reason, don't run the stop-hooks.
1615 size_t num_exe_ctx = exc_ctx_with_reasons.size();
1616 if (num_exe_ctx == 0)
1617 return;
1618
Jim Ingham5b52f0c2011-06-02 23:58:261619 result.SetImmediateOutputStream (m_debugger.GetAsyncOutputStream());
1620 result.SetImmediateErrorStream (m_debugger.GetAsyncErrorStream());
Jim Ingham9575d842011-03-11 03:53:591621
1622 bool keep_going = true;
1623 bool hooks_ran = false;
Jim Ingham381e25b2011-03-22 01:47:271624 bool print_hook_header;
1625 bool print_thread_header;
1626
1627 if (num_exe_ctx == 1)
1628 print_thread_header = false;
1629 else
1630 print_thread_header = true;
1631
1632 if (m_stop_hooks.size() == 1)
1633 print_hook_header = false;
1634 else
1635 print_hook_header = true;
1636
Jim Ingham9575d842011-03-11 03:53:591637 for (pos = m_stop_hooks.begin(); keep_going && pos != end; pos++)
1638 {
1639 // result.Clear();
1640 StopHookSP cur_hook_sp = (*pos).second;
1641 if (!cur_hook_sp->IsActive())
1642 continue;
1643
1644 bool any_thread_matched = false;
1645 for (size_t i = 0; keep_going && i < num_exe_ctx; i++)
1646 {
1647 if ((cur_hook_sp->GetSpecifier () == NULL
1648 || cur_hook_sp->GetSpecifier()->SymbolContextMatches(sym_ctx_with_reasons[i]))
1649 && (cur_hook_sp->GetThreadSpecifier() == NULL
Greg Claytonc14ee322011-09-22 04:58:261650 || cur_hook_sp->GetThreadSpecifier()->ThreadPassesBasicTests(exc_ctx_with_reasons[i].GetThreadPtr())))
Jim Ingham9575d842011-03-11 03:53:591651 {
1652 if (!hooks_ran)
1653 {
Jim Ingham381e25b2011-03-22 01:47:271654 result.AppendMessage("\n** Stop Hooks **");
Jim Ingham9575d842011-03-11 03:53:591655 hooks_ran = true;
1656 }
Jim Ingham381e25b2011-03-22 01:47:271657 if (print_hook_header && !any_thread_matched)
Jim Ingham9575d842011-03-11 03:53:591658 {
1659 result.AppendMessageWithFormat("\n- Hook %d\n", cur_hook_sp->GetID());
1660 any_thread_matched = true;
1661 }
1662
Jim Ingham381e25b2011-03-22 01:47:271663 if (print_thread_header)
Greg Claytonc14ee322011-09-22 04:58:261664 result.AppendMessageWithFormat("-- Thread %d\n", exc_ctx_with_reasons[i].GetThreadPtr()->GetIndexID());
Jim Ingham9575d842011-03-11 03:53:591665
1666 bool stop_on_continue = true;
1667 bool stop_on_error = true;
1668 bool echo_commands = false;
1669 bool print_results = true;
1670 GetDebugger().GetCommandInterpreter().HandleCommands (cur_hook_sp->GetCommands(),
Greg Clayton32e0a752011-03-30 18:16:511671 &exc_ctx_with_reasons[i],
1672 stop_on_continue,
1673 stop_on_error,
1674 echo_commands,
1675 print_results,
1676 result);
Jim Ingham9575d842011-03-11 03:53:591677
1678 // If the command started the target going again, we should bag out of
1679 // running the stop hooks.
Greg Clayton32e0a752011-03-30 18:16:511680 if ((result.GetStatus() == eReturnStatusSuccessContinuingNoResult) ||
1681 (result.GetStatus() == eReturnStatusSuccessContinuingResult))
Jim Ingham9575d842011-03-11 03:53:591682 {
1683 result.AppendMessageWithFormat ("Aborting stop hooks, hook %d set the program running.", cur_hook_sp->GetID());
1684 keep_going = false;
1685 }
1686 }
1687 }
1688 }
1689 if (hooks_ran)
1690 result.AppendMessage ("\n** End Stop Hooks **\n");
Caroline Tice969ed3d12011-05-02 20:41:461691
1692 result.GetImmediateOutputStream()->Flush();
1693 result.GetImmediateErrorStream()->Flush();
Jim Ingham9575d842011-03-11 03:53:591694}
1695
Greg Clayton7b242382011-07-08 00:48:091696bool
1697Target::LoadModuleWithSlide (Module *module, lldb::addr_t slide)
1698{
1699 bool changed = false;
1700 if (module)
1701 {
1702 ObjectFile *object_file = module->GetObjectFile();
1703 if (object_file)
1704 {
1705 SectionList *section_list = object_file->GetSectionList ();
1706 if (section_list)
1707 {
1708 // All sections listed in the dyld image info structure will all
1709 // either be fixed up already, or they will all be off by a single
1710 // slide amount that is determined by finding the first segment
1711 // that is at file offset zero which also has bytes (a file size
1712 // that is greater than zero) in the object file.
1713
1714 // Determine the slide amount (if any)
1715 const size_t num_sections = section_list->GetSize();
1716 size_t sect_idx = 0;
1717 for (sect_idx = 0; sect_idx < num_sections; ++sect_idx)
1718 {
1719 // Iterate through the object file sections to find the
1720 // first section that starts of file offset zero and that
1721 // has bytes in the file...
1722 Section *section = section_list->GetSectionAtIndex (sect_idx).get();
1723 if (section)
1724 {
1725 if (m_section_load_list.SetSectionLoadAddress (section, section->GetFileAddress() + slide))
1726 changed = true;
1727 }
1728 }
1729 }
1730 }
1731 }
1732 return changed;
1733}
1734
1735
Jim Ingham9575d842011-03-11 03:53:591736//--------------------------------------------------------------
1737// class Target::StopHook
1738//--------------------------------------------------------------
1739
1740
1741Target::StopHook::StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid) :
1742 UserID (uid),
1743 m_target_sp (target_sp),
Jim Ingham9575d842011-03-11 03:53:591744 m_commands (),
1745 m_specifier_sp (),
Stephen Wilson71c21d12011-04-11 19:41:401746 m_thread_spec_ap(NULL),
1747 m_active (true)
Jim Ingham9575d842011-03-11 03:53:591748{
1749}
1750
1751Target::StopHook::StopHook (const StopHook &rhs) :
1752 UserID (rhs.GetID()),
1753 m_target_sp (rhs.m_target_sp),
1754 m_commands (rhs.m_commands),
1755 m_specifier_sp (rhs.m_specifier_sp),
Stephen Wilson71c21d12011-04-11 19:41:401756 m_thread_spec_ap (NULL),
1757 m_active (rhs.m_active)
Jim Ingham9575d842011-03-11 03:53:591758{
1759 if (rhs.m_thread_spec_ap.get() != NULL)
1760 m_thread_spec_ap.reset (new ThreadSpec(*rhs.m_thread_spec_ap.get()));
1761}
1762
1763
1764Target::StopHook::~StopHook ()
1765{
1766}
1767
1768void
1769Target::StopHook::SetThreadSpecifier (ThreadSpec *specifier)
1770{
1771 m_thread_spec_ap.reset (specifier);
1772}
1773
1774
1775void
1776Target::StopHook::GetDescription (Stream *s, lldb::DescriptionLevel level) const
1777{
1778 int indent_level = s->GetIndentLevel();
1779
1780 s->SetIndentLevel(indent_level + 2);
1781
1782 s->Printf ("Hook: %d\n", GetID());
1783 if (m_active)
1784 s->Indent ("State: enabled\n");
1785 else
1786 s->Indent ("State: disabled\n");
1787
1788 if (m_specifier_sp)
1789 {
1790 s->Indent();
1791 s->PutCString ("Specifier:\n");
1792 s->SetIndentLevel (indent_level + 4);
1793 m_specifier_sp->GetDescription (s, level);
1794 s->SetIndentLevel (indent_level + 2);
1795 }
1796
1797 if (m_thread_spec_ap.get() != NULL)
1798 {
1799 StreamString tmp;
1800 s->Indent("Thread:\n");
1801 m_thread_spec_ap->GetDescription (&tmp, level);
1802 s->SetIndentLevel (indent_level + 4);
1803 s->Indent (tmp.GetData());
1804 s->PutCString ("\n");
1805 s->SetIndentLevel (indent_level + 2);
1806 }
1807
1808 s->Indent ("Commands: \n");
1809 s->SetIndentLevel (indent_level + 4);
1810 uint32_t num_commands = m_commands.GetSize();
1811 for (uint32_t i = 0; i < num_commands; i++)
1812 {
1813 s->Indent(m_commands.GetStringAtIndex(i));
1814 s->PutCString ("\n");
1815 }
1816 s->SetIndentLevel (indent_level);
1817}
1818
1819
Caroline Ticedaccaa92010-09-20 20:44:431820//--------------------------------------------------------------
1821// class Target::SettingsController
1822//--------------------------------------------------------------
1823
1824Target::SettingsController::SettingsController () :
1825 UserSettingsController ("target", Debugger::GetSettingsController()),
1826 m_default_architecture ()
1827{
1828 m_default_settings.reset (new TargetInstanceSettings (*this, false,
1829 InstanceSettings::GetDefaultName().AsCString()));
1830}
1831
1832Target::SettingsController::~SettingsController ()
1833{
1834}
1835
1836lldb::InstanceSettingsSP
1837Target::SettingsController::CreateInstanceSettings (const char *instance_name)
1838{
Greg Claytondbe54502010-11-19 03:46:011839 TargetInstanceSettings *new_settings = new TargetInstanceSettings (*GetSettingsController(),
1840 false,
1841 instance_name);
Caroline Ticedaccaa92010-09-20 20:44:431842 lldb::InstanceSettingsSP new_settings_sp (new_settings);
1843 return new_settings_sp;
1844}
1845
Caroline Ticedaccaa92010-09-20 20:44:431846
Jim Ingham78a685a2011-04-16 00:01:131847#define TSC_DEFAULT_ARCH "default-arch"
1848#define TSC_EXPR_PREFIX "expr-prefix"
Jim Ingham78a685a2011-04-16 00:01:131849#define TSC_PREFER_DYNAMIC "prefer-dynamic-value"
Greg Clayton385aa282011-04-22 03:55:061850#define TSC_SKIP_PROLOGUE "skip-prologue"
Greg Clayton7e14f912011-04-23 02:04:551851#define TSC_SOURCE_MAP "source-map"
Enrico Granata22c55d12011-08-12 02:00:061852#define TSC_MAX_CHILDREN "max-children-count"
Enrico Granata9128ee2f2011-09-06 19:20:511853#define TSC_MAX_STRLENSUMMARY "max-string-summary-length"
Greg Claytonbfe5f3b2011-02-18 01:44:251854
1855
1856static const ConstString &
1857GetSettingNameForDefaultArch ()
1858{
1859 static ConstString g_const_string (TSC_DEFAULT_ARCH);
Greg Claytonbfe5f3b2011-02-18 01:44:251860 return g_const_string;
Caroline Ticedaccaa92010-09-20 20:44:431861}
1862
Greg Claytonbfe5f3b2011-02-18 01:44:251863static const ConstString &
1864GetSettingNameForExpressionPrefix ()
1865{
1866 static ConstString g_const_string (TSC_EXPR_PREFIX);
1867 return g_const_string;
1868}
1869
1870static const ConstString &
Jim Ingham78a685a2011-04-16 00:01:131871GetSettingNameForPreferDynamicValue ()
1872{
1873 static ConstString g_const_string (TSC_PREFER_DYNAMIC);
1874 return g_const_string;
1875}
1876
Greg Clayton7e14f912011-04-23 02:04:551877static const ConstString &
1878GetSettingNameForSourcePathMap ()
1879{
1880 static ConstString g_const_string (TSC_SOURCE_MAP);
1881 return g_const_string;
1882}
Greg Claytonbfe5f3b2011-02-18 01:44:251883
Greg Clayton385aa282011-04-22 03:55:061884static const ConstString &
1885GetSettingNameForSkipPrologue ()
1886{
1887 static ConstString g_const_string (TSC_SKIP_PROLOGUE);
1888 return g_const_string;
1889}
1890
Enrico Granata22c55d12011-08-12 02:00:061891static const ConstString &
1892GetSettingNameForMaxChildren ()
1893{
1894 static ConstString g_const_string (TSC_MAX_CHILDREN);
1895 return g_const_string;
1896}
Greg Clayton385aa282011-04-22 03:55:061897
Enrico Granata9128ee2f2011-09-06 19:20:511898static const ConstString &
1899GetSettingNameForMaxStringSummaryLength ()
1900{
1901 static ConstString g_const_string (TSC_MAX_STRLENSUMMARY);
1902 return g_const_string;
1903}
Greg Clayton385aa282011-04-22 03:55:061904
Caroline Ticedaccaa92010-09-20 20:44:431905bool
1906Target::SettingsController::SetGlobalVariable (const ConstString &var_name,
1907 const char *index_value,
1908 const char *value,
1909 const SettingEntry &entry,
Greg Claytone0d378b2011-03-24 21:19:541910 const VarSetOperationType op,
Caroline Ticedaccaa92010-09-20 20:44:431911 Error&err)
1912{
Greg Claytonbfe5f3b2011-02-18 01:44:251913 if (var_name == GetSettingNameForDefaultArch())
Caroline Ticedaccaa92010-09-20 20:44:431914 {
Greg Claytoneb0103f2011-04-07 22:46:351915 m_default_architecture.SetTriple (value, NULL);
Greg Clayton64195a22011-02-23 00:35:021916 if (!m_default_architecture.IsValid())
1917 err.SetErrorStringWithFormat ("'%s' is not a valid architecture or triple.", value);
Caroline Ticedaccaa92010-09-20 20:44:431918 }
1919 return true;
1920}
1921
1922
1923bool
1924Target::SettingsController::GetGlobalVariable (const ConstString &var_name,
1925 StringList &value,
1926 Error &err)
1927{
Greg Claytonbfe5f3b2011-02-18 01:44:251928 if (var_name == GetSettingNameForDefaultArch())
Caroline Ticedaccaa92010-09-20 20:44:431929 {
Greg Clayton307de252010-10-27 02:06:371930 // If the arch is invalid (the default), don't show a string for it
1931 if (m_default_architecture.IsValid())
Greg Clayton64195a22011-02-23 00:35:021932 value.AppendString (m_default_architecture.GetArchitectureName());
Caroline Ticedaccaa92010-09-20 20:44:431933 return true;
1934 }
1935 else
1936 err.SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
1937
1938 return false;
1939}
1940
1941//--------------------------------------------------------------
1942// class TargetInstanceSettings
1943//--------------------------------------------------------------
1944
Greg Clayton85851dd2010-12-04 00:10:171945TargetInstanceSettings::TargetInstanceSettings
1946(
1947 UserSettingsController &owner,
1948 bool live_instance,
1949 const char *name
1950) :
Greg Claytonbfe5f3b2011-02-18 01:44:251951 InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
Greg Clayton7e14f912011-04-23 02:04:551952 m_expr_prefix_file (),
1953 m_expr_prefix_contents_sp (),
Jim Ingham2837b762011-05-04 03:43:181954 m_prefer_dynamic_value (2),
Greg Clayton7e14f912011-04-23 02:04:551955 m_skip_prologue (true, true),
Enrico Granata22c55d12011-08-12 02:00:061956 m_source_map (NULL, NULL),
Enrico Granata9128ee2f2011-09-06 19:20:511957 m_max_children_display(256),
1958 m_max_strlen_length(1024)
Caroline Ticedaccaa92010-09-20 20:44:431959{
1960 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
1961 // until the vtables for TargetInstanceSettings are properly set up, i.e. AFTER all the initializers.
1962 // For this reason it has to be called here, rather than in the initializer or in the parent constructor.
1963 // This is true for CreateInstanceName() too.
1964
1965 if (GetInstanceName () == InstanceSettings::InvalidName())
1966 {
1967 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
1968 m_owner.RegisterInstanceSettings (this);
1969 }
1970
1971 if (live_instance)
1972 {
1973 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1974 CopyInstanceSettings (pending_settings,false);
Caroline Ticedaccaa92010-09-20 20:44:431975 }
1976}
1977
1978TargetInstanceSettings::TargetInstanceSettings (const TargetInstanceSettings &rhs) :
Greg Clayton7e14f912011-04-23 02:04:551979 InstanceSettings (*Target::GetSettingsController(), CreateInstanceName().AsCString()),
1980 m_expr_prefix_file (rhs.m_expr_prefix_file),
1981 m_expr_prefix_contents_sp (rhs.m_expr_prefix_contents_sp),
1982 m_prefer_dynamic_value (rhs.m_prefer_dynamic_value),
1983 m_skip_prologue (rhs.m_skip_prologue),
Enrico Granata22c55d12011-08-12 02:00:061984 m_source_map (rhs.m_source_map),
Enrico Granata9128ee2f2011-09-06 19:20:511985 m_max_children_display(rhs.m_max_children_display),
1986 m_max_strlen_length(rhs.m_max_strlen_length)
Caroline Ticedaccaa92010-09-20 20:44:431987{
1988 if (m_instance_name != InstanceSettings::GetDefaultName())
1989 {
1990 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1991 CopyInstanceSettings (pending_settings,false);
Caroline Ticedaccaa92010-09-20 20:44:431992 }
1993}
1994
1995TargetInstanceSettings::~TargetInstanceSettings ()
1996{
1997}
1998
1999TargetInstanceSettings&
2000TargetInstanceSettings::operator= (const TargetInstanceSettings &rhs)
2001{
2002 if (this != &rhs)
2003 {
2004 }
2005
2006 return *this;
2007}
2008
Caroline Ticedaccaa92010-09-20 20:44:432009void
2010TargetInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
2011 const char *index_value,
2012 const char *value,
2013 const ConstString &instance_name,
2014 const SettingEntry &entry,
Greg Claytone0d378b2011-03-24 21:19:542015 VarSetOperationType op,
Caroline Ticedaccaa92010-09-20 20:44:432016 Error &err,
2017 bool pending)
2018{
Greg Claytonbfe5f3b2011-02-18 01:44:252019 if (var_name == GetSettingNameForExpressionPrefix ())
Sean Callanan322f5292010-10-29 00:29:032020 {
Greg Clayton7e14f912011-04-23 02:04:552021 err = UserSettingsController::UpdateFileSpecOptionValue (value, op, m_expr_prefix_file);
2022 if (err.Success())
Sean Callanan322f5292010-10-29 00:29:032023 {
Greg Clayton7e14f912011-04-23 02:04:552024 switch (op)
Sean Callanan322f5292010-10-29 00:29:032025 {
Greg Clayton7e14f912011-04-23 02:04:552026 default:
2027 break;
2028 case eVarSetOperationAssign:
2029 case eVarSetOperationAppend:
Sean Callanan322f5292010-10-29 00:29:032030 {
Greg Clayton7e14f912011-04-23 02:04:552031 if (!m_expr_prefix_file.GetCurrentValue().Exists())
2032 {
2033 err.SetErrorToGenericError ();
2034 err.SetErrorStringWithFormat ("%s does not exist.\n", value);
2035 return;
2036 }
2037
2038 m_expr_prefix_contents_sp = m_expr_prefix_file.GetCurrentValue().ReadFileContents();
2039
2040 if (!m_expr_prefix_contents_sp && m_expr_prefix_contents_sp->GetByteSize() == 0)
2041 {
2042 err.SetErrorStringWithFormat ("Couldn't read data from '%s'\n", value);
2043 m_expr_prefix_contents_sp.reset();
2044 }
Sean Callanan322f5292010-10-29 00:29:032045 }
Greg Clayton7e14f912011-04-23 02:04:552046 break;
2047 case eVarSetOperationClear:
2048 m_expr_prefix_contents_sp.reset();
Sean Callanan322f5292010-10-29 00:29:032049 }
Sean Callanan322f5292010-10-29 00:29:032050 }
2051 }
Jim Ingham78a685a2011-04-16 00:01:132052 else if (var_name == GetSettingNameForPreferDynamicValue())
2053 {
Jim Ingham2837b762011-05-04 03:43:182054 int new_value;
2055 UserSettingsController::UpdateEnumVariable (g_dynamic_value_types, &new_value, value, err);
2056 if (err.Success())
2057 m_prefer_dynamic_value = new_value;
Greg Clayton385aa282011-04-22 03:55:062058 }
2059 else if (var_name == GetSettingNameForSkipPrologue())
2060 {
Greg Clayton7e14f912011-04-23 02:04:552061 err = UserSettingsController::UpdateBooleanOptionValue (value, op, m_skip_prologue);
2062 }
Enrico Granata22c55d12011-08-12 02:00:062063 else if (var_name == GetSettingNameForMaxChildren())
2064 {
2065 bool ok;
2066 uint32_t new_value = Args::StringToUInt32(value, 0, 10, &ok);
2067 if (ok)
2068 m_max_children_display = new_value;
2069 }
Enrico Granata9128ee2f2011-09-06 19:20:512070 else if (var_name == GetSettingNameForMaxStringSummaryLength())
2071 {
2072 bool ok;
2073 uint32_t new_value = Args::StringToUInt32(value, 0, 10, &ok);
2074 if (ok)
2075 m_max_strlen_length = new_value;
2076 }
Greg Clayton7e14f912011-04-23 02:04:552077 else if (var_name == GetSettingNameForSourcePathMap ())
2078 {
2079 switch (op)
2080 {
2081 case eVarSetOperationReplace:
2082 case eVarSetOperationInsertBefore:
2083 case eVarSetOperationInsertAfter:
2084 case eVarSetOperationRemove:
2085 default:
2086 break;
2087 case eVarSetOperationAssign:
2088 m_source_map.Clear(true);
2089 // Fall through to append....
2090 case eVarSetOperationAppend:
2091 {
2092 Args args(value);
2093 const uint32_t argc = args.GetArgumentCount();
2094 if (argc & 1 || argc == 0)
2095 {
2096 err.SetErrorStringWithFormat ("an even number of paths must be supplied to to the source-map setting: %u arguments given", argc);
2097 }
2098 else
2099 {
2100 char resolved_new_path[PATH_MAX];
2101 FileSpec file_spec;
2102 const char *old_path;
2103 for (uint32_t idx = 0; (old_path = args.GetArgumentAtIndex(idx)) != NULL; idx += 2)
2104 {
2105 const char *new_path = args.GetArgumentAtIndex(idx+1);
2106 assert (new_path); // We have an even number of paths, this shouldn't happen!
2107
2108 file_spec.SetFile(new_path, true);
2109 if (file_spec.Exists())
2110 {
2111 if (file_spec.GetPath (resolved_new_path, sizeof(resolved_new_path)) >= sizeof(resolved_new_path))
2112 {
2113 err.SetErrorStringWithFormat("new path '%s' is too long", new_path);
2114 return;
2115 }
2116 }
2117 else
2118 {
2119 err.SetErrorStringWithFormat("new path '%s' doesn't exist", new_path);
2120 return;
2121 }
2122 m_source_map.Append(ConstString (old_path), ConstString (resolved_new_path), true);
2123 }
2124 }
2125 }
2126 break;
2127
2128 case eVarSetOperationClear:
2129 m_source_map.Clear(true);
2130 break;
2131 }
Jim Ingham78a685a2011-04-16 00:01:132132 }
Caroline Ticedaccaa92010-09-20 20:44:432133}
2134
2135void
Greg Claytonbfe5f3b2011-02-18 01:44:252136TargetInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings, bool pending)
Caroline Ticedaccaa92010-09-20 20:44:432137{
Sean Callanan322f5292010-10-29 00:29:032138 TargetInstanceSettings *new_settings_ptr = static_cast <TargetInstanceSettings *> (new_settings.get());
2139
2140 if (!new_settings_ptr)
2141 return;
2142
Greg Clayton7e14f912011-04-23 02:04:552143 m_expr_prefix_file = new_settings_ptr->m_expr_prefix_file;
2144 m_expr_prefix_contents_sp = new_settings_ptr->m_expr_prefix_contents_sp;
2145 m_prefer_dynamic_value = new_settings_ptr->m_prefer_dynamic_value;
2146 m_skip_prologue = new_settings_ptr->m_skip_prologue;
Enrico Granata22c55d12011-08-12 02:00:062147 m_max_children_display = new_settings_ptr->m_max_children_display;
Enrico Granata9128ee2f2011-09-06 19:20:512148 m_max_strlen_length = new_settings_ptr->m_max_strlen_length;
Caroline Ticedaccaa92010-09-20 20:44:432149}
2150
Caroline Tice12cecd72010-09-20 21:37:422151bool
Caroline Ticedaccaa92010-09-20 20:44:432152TargetInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
2153 const ConstString &var_name,
2154 StringList &value,
Caroline Tice12cecd72010-09-20 21:37:422155 Error *err)
Caroline Ticedaccaa92010-09-20 20:44:432156{
Greg Claytonbfe5f3b2011-02-18 01:44:252157 if (var_name == GetSettingNameForExpressionPrefix ())
Sean Callanan322f5292010-10-29 00:29:032158 {
Greg Clayton7e14f912011-04-23 02:04:552159 char path[PATH_MAX];
2160 const size_t path_len = m_expr_prefix_file.GetCurrentValue().GetPath (path, sizeof(path));
2161 if (path_len > 0)
2162 value.AppendString (path, path_len);
Sean Callanan322f5292010-10-29 00:29:032163 }
Jim Ingham78a685a2011-04-16 00:01:132164 else if (var_name == GetSettingNameForPreferDynamicValue())
2165 {
Jim Ingham2837b762011-05-04 03:43:182166 value.AppendString (g_dynamic_value_types[m_prefer_dynamic_value].string_value);
Jim Ingham78a685a2011-04-16 00:01:132167 }
Greg Clayton385aa282011-04-22 03:55:062168 else if (var_name == GetSettingNameForSkipPrologue())
2169 {
2170 if (m_skip_prologue)
2171 value.AppendString ("true");
2172 else
2173 value.AppendString ("false");
2174 }
Greg Clayton7e14f912011-04-23 02:04:552175 else if (var_name == GetSettingNameForSourcePathMap ())
2176 {
2177 }
Enrico Granata22c55d12011-08-12 02:00:062178 else if (var_name == GetSettingNameForMaxChildren())
2179 {
2180 StreamString count_str;
2181 count_str.Printf ("%d", m_max_children_display);
2182 value.AppendString (count_str.GetData());
2183 }
Enrico Granata9128ee2f2011-09-06 19:20:512184 else if (var_name == GetSettingNameForMaxStringSummaryLength())
2185 {
2186 StreamString count_str;
2187 count_str.Printf ("%d", m_max_strlen_length);
2188 value.AppendString (count_str.GetData());
2189 }
Sean Callanan322f5292010-10-29 00:29:032190 else
2191 {
2192 if (err)
2193 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
2194 return false;
2195 }
2196
2197 return true;
Caroline Ticedaccaa92010-09-20 20:44:432198}
2199
2200const ConstString
2201TargetInstanceSettings::CreateInstanceName ()
2202{
Caroline Ticedaccaa92010-09-20 20:44:432203 StreamString sstr;
Caroline Tice1559a462010-09-27 00:30:102204 static int instance_count = 1;
2205
Caroline Ticedaccaa92010-09-20 20:44:432206 sstr.Printf ("target_%d", instance_count);
2207 ++instance_count;
2208
2209 const ConstString ret_val (sstr.GetData());
2210 return ret_val;
2211}
2212
2213//--------------------------------------------------
2214// Target::SettingsController Variable Tables
2215//--------------------------------------------------
Jim Ingham2837b762011-05-04 03:43:182216OptionEnumValueElement
2217TargetInstanceSettings::g_dynamic_value_types[] =
2218{
Greg Clayton5d2fbfe2011-05-30 00:39:482219{ eNoDynamicValues, "no-dynamic-values", "Don't calculate the dynamic type of values"},
2220{ eDynamicCanRunTarget, "run-target", "Calculate the dynamic type of values even if you have to run the target."},
2221{ eDynamicDontRunTarget, "no-run-target", "Calculate the dynamic type of values, but don't run the target."},
Jim Ingham2837b762011-05-04 03:43:182222{ 0, NULL, NULL }
2223};
Caroline Ticedaccaa92010-09-20 20:44:432224
2225SettingEntry
2226Target::SettingsController::global_settings_table[] =
2227{
Greg Claytonbfe5f3b2011-02-18 01:44:252228 // var-name var-type default enum init'd hidden help-text
2229 // ================= ================== =========== ==== ====== ====== =========================================================================
2230 { TSC_DEFAULT_ARCH , eSetVarTypeString , NULL , NULL, false, false, "Default architecture to choose, when there's a choice." },
2231 { NULL , eSetVarTypeNone , NULL , NULL, false, false, NULL }
2232};
2233
Caroline Ticedaccaa92010-09-20 20:44:432234SettingEntry
2235Target::SettingsController::instance_settings_table[] =
2236{
Enrico Granata9128ee2f2011-09-06 19:20:512237 // var-name var-type default enum init'd hidden help-text
2238 // ================= ================== =============== ======================= ====== ====== =========================================================================
2239 { TSC_EXPR_PREFIX , eSetVarTypeString , NULL , NULL, false, false, "Path to a file containing expressions to be prepended to all expressions." },
2240 { TSC_PREFER_DYNAMIC , eSetVarTypeEnum , NULL , g_dynamic_value_types, false, false, "Should printed values be shown as their dynamic value." },
2241 { TSC_SKIP_PROLOGUE , eSetVarTypeBoolean, "true" , NULL, false, false, "Skip function prologues when setting breakpoints by name." },
2242 { TSC_SOURCE_MAP , eSetVarTypeArray , NULL , NULL, false, false, "Source path remappings to use when locating source files from debug information." },
2243 { TSC_MAX_CHILDREN , eSetVarTypeInt , "256" , NULL, true, false, "Maximum number of children to expand in any level of depth." },
2244 { TSC_MAX_STRLENSUMMARY , eSetVarTypeInt , "1024" , NULL, true, false, "Maximum number of characters to show when using %s in summary strings." },
2245 { NULL , eSetVarTypeNone , NULL , NULL, false, false, NULL }
Caroline Ticedaccaa92010-09-20 20:44:432246};