Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- Target.cpp ----------------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "lldb/Target/Target.h" |
| 11 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
| 16 | #include "lldb/Breakpoint/BreakpointResolver.h" |
| 17 | #include "lldb/Breakpoint/BreakpointResolverAddress.h" |
| 18 | #include "lldb/Breakpoint/BreakpointResolverFileLine.h" |
| 19 | #include "lldb/Breakpoint/BreakpointResolverName.h" |
Sean Callanan | 77e9394 | 2010-10-29 00:29:03 +0000 | [diff] [blame] | 20 | #include "lldb/Core/DataBufferMemoryMap.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 21 | #include "lldb/Core/Event.h" |
| 22 | #include "lldb/Core/Log.h" |
| 23 | #include "lldb/Core/Timer.h" |
| 24 | #include "lldb/Core/StreamString.h" |
| 25 | #include "lldb/Host/Host.h" |
| 26 | #include "lldb/lldb-private-log.h" |
| 27 | #include "lldb/Symbol/ObjectFile.h" |
| 28 | #include "lldb/Target/Process.h" |
| 29 | #include "lldb/Core/Debugger.h" |
| 30 | |
| 31 | using namespace lldb; |
| 32 | using namespace lldb_private; |
| 33 | |
| 34 | //---------------------------------------------------------------------- |
| 35 | // Target constructor |
| 36 | //---------------------------------------------------------------------- |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 37 | Target::Target(Debugger &debugger) : |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 38 | Broadcaster("lldb.target"), |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 39 | TargetInstanceSettings (*(Target::GetSettingsController().get())), |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 40 | m_debugger (debugger), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 41 | m_images(), |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 42 | m_section_load_list (), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 43 | m_breakpoint_list (false), |
| 44 | m_internal_breakpoint_list (true), |
| 45 | m_process_sp(), |
| 46 | m_triple(), |
| 47 | m_search_filter_sp(), |
| 48 | m_image_search_paths (ImageSearchPathsChanged, this), |
| 49 | m_scratch_ast_context_ap(NULL) |
| 50 | { |
Greg Clayton | 49ce682 | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 51 | SetEventName (eBroadcastBitBreakpointChanged, "breakpoint-changed"); |
| 52 | SetEventName (eBroadcastBitModulesLoaded, "modules-loaded"); |
| 53 | SetEventName (eBroadcastBitModulesUnloaded, "modules-unloaded"); |
| 54 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 55 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT); |
| 56 | if (log) |
| 57 | log->Printf ("%p Target::Target()", this); |
| 58 | } |
| 59 | |
| 60 | //---------------------------------------------------------------------- |
| 61 | // Destructor |
| 62 | //---------------------------------------------------------------------- |
| 63 | Target::~Target() |
| 64 | { |
| 65 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT); |
| 66 | if (log) |
| 67 | log->Printf ("%p Target::~Target()", this); |
| 68 | DeleteCurrentProcess (); |
| 69 | } |
| 70 | |
| 71 | void |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 72 | Target::Dump (Stream *s, lldb::DescriptionLevel description_level) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 73 | { |
Greg Clayton | 3fed8b9 | 2010-10-08 00:21:05 +0000 | [diff] [blame] | 74 | // s->Printf("%.*p: ", (int)sizeof(void*) * 2, this); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 75 | if (description_level != lldb::eDescriptionLevelBrief) |
| 76 | { |
| 77 | s->Indent(); |
| 78 | s->PutCString("Target\n"); |
| 79 | s->IndentMore(); |
Greg Clayton | 3f5ee7f | 2010-10-29 04:59:35 +0000 | [diff] [blame] | 80 | m_images.Dump(s); |
| 81 | m_breakpoint_list.Dump(s); |
| 82 | m_internal_breakpoint_list.Dump(s); |
| 83 | s->IndentLess(); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 84 | } |
| 85 | else |
| 86 | { |
Greg Clayton | a66ba46 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 87 | s->PutCString (GetExecutableModule()->GetFileSpec().GetFilename().GetCString()); |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 88 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | void |
| 92 | Target::DeleteCurrentProcess () |
| 93 | { |
| 94 | if (m_process_sp.get()) |
| 95 | { |
Greg Clayton | 49480b1 | 2010-09-14 23:52:43 +0000 | [diff] [blame] | 96 | m_section_load_list.Clear(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 97 | if (m_process_sp->IsAlive()) |
| 98 | m_process_sp->Destroy(); |
| 99 | else |
| 100 | m_process_sp->Finalize(); |
| 101 | |
| 102 | // Do any cleanup of the target we need to do between process instances. |
| 103 | // NB It is better to do this before destroying the process in case the |
| 104 | // clean up needs some help from the process. |
| 105 | m_breakpoint_list.ClearAllBreakpointSites(); |
| 106 | m_internal_breakpoint_list.ClearAllBreakpointSites(); |
| 107 | m_process_sp.reset(); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | const lldb::ProcessSP & |
| 112 | Target::CreateProcess (Listener &listener, const char *plugin_name) |
| 113 | { |
| 114 | DeleteCurrentProcess (); |
| 115 | m_process_sp.reset(Process::FindPlugin(*this, plugin_name, listener)); |
| 116 | return m_process_sp; |
| 117 | } |
| 118 | |
| 119 | const lldb::ProcessSP & |
| 120 | Target::GetProcessSP () const |
| 121 | { |
| 122 | return m_process_sp; |
| 123 | } |
| 124 | |
| 125 | lldb::TargetSP |
| 126 | Target::GetSP() |
| 127 | { |
Greg Clayton | 63094e0 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 128 | return m_debugger.GetTargetList().GetTargetSP(this); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | BreakpointList & |
| 132 | Target::GetBreakpointList(bool internal) |
| 133 | { |
| 134 | if (internal) |
| 135 | return m_internal_breakpoint_list; |
| 136 | else |
| 137 | return m_breakpoint_list; |
| 138 | } |
| 139 | |
| 140 | const BreakpointList & |
| 141 | Target::GetBreakpointList(bool internal) const |
| 142 | { |
| 143 | if (internal) |
| 144 | return m_internal_breakpoint_list; |
| 145 | else |
| 146 | return m_breakpoint_list; |
| 147 | } |
| 148 | |
| 149 | BreakpointSP |
| 150 | Target::GetBreakpointByID (break_id_t break_id) |
| 151 | { |
| 152 | BreakpointSP bp_sp; |
| 153 | |
| 154 | if (LLDB_BREAK_ID_IS_INTERNAL (break_id)) |
| 155 | bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id); |
| 156 | else |
| 157 | bp_sp = m_breakpoint_list.FindBreakpointByID (break_id); |
| 158 | |
| 159 | return bp_sp; |
| 160 | } |
| 161 | |
| 162 | BreakpointSP |
| 163 | Target::CreateBreakpoint (const FileSpec *containingModule, const FileSpec &file, uint32_t line_no, bool check_inlines, bool internal) |
| 164 | { |
| 165 | SearchFilterSP filter_sp(GetSearchFilterForModule (containingModule)); |
| 166 | BreakpointResolverSP resolver_sp(new BreakpointResolverFileLine (NULL, file, line_no, check_inlines)); |
| 167 | return CreateBreakpoint (filter_sp, resolver_sp, internal); |
| 168 | } |
| 169 | |
| 170 | |
| 171 | BreakpointSP |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 172 | Target::CreateBreakpoint (lldb::addr_t addr, bool internal) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 173 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 174 | Address so_addr; |
| 175 | // Attempt to resolve our load address if possible, though it is ok if |
| 176 | // it doesn't resolve to section/offset. |
| 177 | |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 178 | // Try and resolve as a load address if possible |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 179 | m_section_load_list.ResolveLoadAddress(addr, so_addr); |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 180 | if (!so_addr.IsValid()) |
| 181 | { |
| 182 | // The address didn't resolve, so just set this as an absolute address |
| 183 | so_addr.SetOffset (addr); |
| 184 | } |
| 185 | BreakpointSP bp_sp (CreateBreakpoint(so_addr, internal)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 186 | return bp_sp; |
| 187 | } |
| 188 | |
| 189 | BreakpointSP |
| 190 | Target::CreateBreakpoint (Address &addr, bool internal) |
| 191 | { |
| 192 | TargetSP target_sp = this->GetSP(); |
| 193 | SearchFilterSP filter_sp(new SearchFilter (target_sp)); |
| 194 | BreakpointResolverSP resolver_sp (new BreakpointResolverAddress (NULL, addr)); |
| 195 | return CreateBreakpoint (filter_sp, resolver_sp, internal); |
| 196 | } |
| 197 | |
| 198 | BreakpointSP |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 199 | Target::CreateBreakpoint (FileSpec *containingModule, const char *func_name, uint32_t func_name_type_mask, bool internal) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 200 | { |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 201 | BreakpointSP bp_sp; |
| 202 | if (func_name) |
| 203 | { |
| 204 | SearchFilterSP filter_sp(GetSearchFilterForModule (containingModule)); |
| 205 | BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL, func_name, func_name_type_mask, Breakpoint::Exact)); |
| 206 | bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal); |
| 207 | } |
| 208 | return bp_sp; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | |
| 212 | SearchFilterSP |
| 213 | Target::GetSearchFilterForModule (const FileSpec *containingModule) |
| 214 | { |
| 215 | SearchFilterSP filter_sp; |
| 216 | lldb::TargetSP target_sp = this->GetSP(); |
| 217 | if (containingModule != NULL) |
| 218 | { |
| 219 | // TODO: We should look into sharing module based search filters |
| 220 | // across many breakpoints like we do for the simple target based one |
| 221 | filter_sp.reset (new SearchFilterByModule (target_sp, *containingModule)); |
| 222 | } |
| 223 | else |
| 224 | { |
| 225 | if (m_search_filter_sp.get() == NULL) |
| 226 | m_search_filter_sp.reset (new SearchFilter (target_sp)); |
| 227 | filter_sp = m_search_filter_sp; |
| 228 | } |
| 229 | return filter_sp; |
| 230 | } |
| 231 | |
| 232 | BreakpointSP |
| 233 | Target::CreateBreakpoint (FileSpec *containingModule, RegularExpression &func_regex, bool internal) |
| 234 | { |
| 235 | SearchFilterSP filter_sp(GetSearchFilterForModule (containingModule)); |
| 236 | BreakpointResolverSP resolver_sp(new BreakpointResolverName (NULL, func_regex)); |
| 237 | |
| 238 | return CreateBreakpoint (filter_sp, resolver_sp, internal); |
| 239 | } |
| 240 | |
| 241 | BreakpointSP |
| 242 | Target::CreateBreakpoint (SearchFilterSP &filter_sp, BreakpointResolverSP &resolver_sp, bool internal) |
| 243 | { |
| 244 | BreakpointSP bp_sp; |
| 245 | if (filter_sp && resolver_sp) |
| 246 | { |
| 247 | bp_sp.reset(new Breakpoint (*this, filter_sp, resolver_sp)); |
| 248 | resolver_sp->SetBreakpoint (bp_sp.get()); |
| 249 | |
| 250 | if (internal) |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 251 | m_internal_breakpoint_list.Add (bp_sp, false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 252 | else |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 253 | m_breakpoint_list.Add (bp_sp, true); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 254 | |
| 255 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS); |
| 256 | if (log) |
| 257 | { |
| 258 | StreamString s; |
| 259 | bp_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose); |
| 260 | log->Printf ("Target::%s (internal = %s) => break_id = %s\n", __FUNCTION__, internal ? "yes" : "no", s.GetData()); |
| 261 | } |
| 262 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 263 | bp_sp->ResolveBreakpoint(); |
| 264 | } |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 265 | |
| 266 | if (!internal && bp_sp) |
| 267 | { |
| 268 | m_last_created_breakpoint = bp_sp; |
| 269 | } |
| 270 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 271 | return bp_sp; |
| 272 | } |
| 273 | |
| 274 | void |
| 275 | Target::RemoveAllBreakpoints (bool internal_also) |
| 276 | { |
| 277 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS); |
| 278 | if (log) |
| 279 | log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no"); |
| 280 | |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 281 | m_breakpoint_list.RemoveAll (true); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 282 | if (internal_also) |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 283 | m_internal_breakpoint_list.RemoveAll (false); |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 284 | |
| 285 | m_last_created_breakpoint.reset(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | void |
| 289 | Target::DisableAllBreakpoints (bool internal_also) |
| 290 | { |
| 291 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS); |
| 292 | if (log) |
| 293 | log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no"); |
| 294 | |
| 295 | m_breakpoint_list.SetEnabledAll (false); |
| 296 | if (internal_also) |
| 297 | m_internal_breakpoint_list.SetEnabledAll (false); |
| 298 | } |
| 299 | |
| 300 | void |
| 301 | Target::EnableAllBreakpoints (bool internal_also) |
| 302 | { |
| 303 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS); |
| 304 | if (log) |
| 305 | log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no"); |
| 306 | |
| 307 | m_breakpoint_list.SetEnabledAll (true); |
| 308 | if (internal_also) |
| 309 | m_internal_breakpoint_list.SetEnabledAll (true); |
| 310 | } |
| 311 | |
| 312 | bool |
| 313 | Target::RemoveBreakpointByID (break_id_t break_id) |
| 314 | { |
| 315 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS); |
| 316 | if (log) |
| 317 | log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no"); |
| 318 | |
| 319 | if (DisableBreakpointByID (break_id)) |
| 320 | { |
| 321 | if (LLDB_BREAK_ID_IS_INTERNAL (break_id)) |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 322 | m_internal_breakpoint_list.Remove(break_id, false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 323 | else |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 324 | { |
| 325 | if (m_last_created_breakpoint->GetID() == break_id) |
| 326 | m_last_created_breakpoint.reset(); |
Greg Clayton | c7f5d5c | 2010-07-23 23:33:17 +0000 | [diff] [blame] | 327 | m_breakpoint_list.Remove(break_id, true); |
Jim Ingham | d168690 | 2010-10-14 23:45:03 +0000 | [diff] [blame] | 328 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 329 | return true; |
| 330 | } |
| 331 | return false; |
| 332 | } |
| 333 | |
| 334 | bool |
| 335 | Target::DisableBreakpointByID (break_id_t break_id) |
| 336 | { |
| 337 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS); |
| 338 | if (log) |
| 339 | log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no"); |
| 340 | |
| 341 | BreakpointSP bp_sp; |
| 342 | |
| 343 | if (LLDB_BREAK_ID_IS_INTERNAL (break_id)) |
| 344 | bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id); |
| 345 | else |
| 346 | bp_sp = m_breakpoint_list.FindBreakpointByID (break_id); |
| 347 | if (bp_sp) |
| 348 | { |
| 349 | bp_sp->SetEnabled (false); |
| 350 | return true; |
| 351 | } |
| 352 | return false; |
| 353 | } |
| 354 | |
| 355 | bool |
| 356 | Target::EnableBreakpointByID (break_id_t break_id) |
| 357 | { |
| 358 | Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS); |
| 359 | if (log) |
| 360 | log->Printf ("Target::%s (break_id = %i, internal = %s)\n", |
| 361 | __FUNCTION__, |
| 362 | break_id, |
| 363 | LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no"); |
| 364 | |
| 365 | BreakpointSP bp_sp; |
| 366 | |
| 367 | if (LLDB_BREAK_ID_IS_INTERNAL (break_id)) |
| 368 | bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id); |
| 369 | else |
| 370 | bp_sp = m_breakpoint_list.FindBreakpointByID (break_id); |
| 371 | |
| 372 | if (bp_sp) |
| 373 | { |
| 374 | bp_sp->SetEnabled (true); |
| 375 | return true; |
| 376 | } |
| 377 | return false; |
| 378 | } |
| 379 | |
| 380 | ModuleSP |
| 381 | Target::GetExecutableModule () |
| 382 | { |
| 383 | ModuleSP executable_sp; |
| 384 | if (m_images.GetSize() > 0) |
| 385 | executable_sp = m_images.GetModuleAtIndex(0); |
| 386 | return executable_sp; |
| 387 | } |
| 388 | |
| 389 | void |
| 390 | Target::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files) |
| 391 | { |
| 392 | m_images.Clear(); |
| 393 | m_scratch_ast_context_ap.reset(); |
| 394 | |
| 395 | if (executable_sp.get()) |
| 396 | { |
| 397 | Timer scoped_timer (__PRETTY_FUNCTION__, |
| 398 | "Target::SetExecutableModule (executable = '%s/%s')", |
| 399 | executable_sp->GetFileSpec().GetDirectory().AsCString(), |
| 400 | executable_sp->GetFileSpec().GetFilename().AsCString()); |
| 401 | |
| 402 | m_images.Append(executable_sp); // The first image is our exectuable file |
| 403 | |
| 404 | ArchSpec exe_arch = executable_sp->GetArchitecture(); |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 405 | // If we haven't set an architecture yet, reset our architecture based on what we found in the executable module. |
| 406 | if (!m_arch_spec.IsValid()) |
| 407 | m_arch_spec = exe_arch; |
| 408 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 409 | FileSpecList dependent_files; |
| 410 | ObjectFile * executable_objfile = executable_sp->GetObjectFile(); |
| 411 | if (executable_objfile == NULL) |
| 412 | { |
| 413 | |
| 414 | FileSpec bundle_executable(executable_sp->GetFileSpec()); |
Greg Clayton | 24b48ff | 2010-10-17 22:03:32 +0000 | [diff] [blame] | 415 | if (Host::ResolveExecutableInBundle (bundle_executable)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 416 | { |
| 417 | ModuleSP bundle_exe_module_sp(GetSharedModule(bundle_executable, |
| 418 | exe_arch)); |
| 419 | SetExecutableModule (bundle_exe_module_sp, get_dependent_files); |
| 420 | if (bundle_exe_module_sp->GetObjectFile() != NULL) |
| 421 | executable_sp = bundle_exe_module_sp; |
| 422 | return; |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | if (executable_objfile) |
| 427 | { |
| 428 | executable_objfile->GetDependentModules(dependent_files); |
| 429 | for (uint32_t i=0; i<dependent_files.GetSize(); i++) |
| 430 | { |
| 431 | ModuleSP image_module_sp(GetSharedModule(dependent_files.GetFileSpecPointerAtIndex(i), |
| 432 | exe_arch)); |
| 433 | if (image_module_sp.get()) |
| 434 | { |
| 435 | //image_module_sp->Dump(&s);// REMOVE THIS, DEBUG ONLY |
| 436 | ObjectFile *objfile = image_module_sp->GetObjectFile(); |
| 437 | if (objfile) |
| 438 | objfile->GetDependentModules(dependent_files); |
| 439 | } |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | // Now see if we know the target triple, and if so, create our scratch AST context: |
| 444 | ConstString target_triple; |
| 445 | if (GetTargetTriple(target_triple)) |
| 446 | { |
| 447 | m_scratch_ast_context_ap.reset (new ClangASTContext(target_triple.GetCString())); |
| 448 | } |
| 449 | } |
Caroline Tice | 1ebef44 | 2010-09-27 00:30:10 +0000 | [diff] [blame] | 450 | |
| 451 | UpdateInstanceName(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | |
| 455 | ModuleList& |
| 456 | Target::GetImages () |
| 457 | { |
| 458 | return m_images; |
| 459 | } |
| 460 | |
| 461 | ArchSpec |
| 462 | Target::GetArchitecture () const |
| 463 | { |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 464 | return m_arch_spec; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 465 | } |
| 466 | |
Jim Ingham | 7508e73 | 2010-08-09 23:31:02 +0000 | [diff] [blame] | 467 | bool |
| 468 | Target::SetArchitecture (const ArchSpec &arch_spec) |
| 469 | { |
| 470 | if (m_arch_spec == arch_spec) |
| 471 | { |
| 472 | // If we're setting the architecture to our current architecture, we |
| 473 | // don't need to do anything. |
| 474 | return true; |
| 475 | } |
| 476 | else if (!m_arch_spec.IsValid()) |
| 477 | { |
| 478 | // If we haven't got a valid arch spec, then we just need to set it. |
| 479 | m_arch_spec = arch_spec; |
| 480 | return true; |
| 481 | } |
| 482 | else |
| 483 | { |
| 484 | // If we have an executable file, try to reset the executable to the desired architecture |
| 485 | m_arch_spec = arch_spec; |
| 486 | ModuleSP executable_sp = GetExecutableModule (); |
| 487 | m_images.Clear(); |
| 488 | m_scratch_ast_context_ap.reset(); |
| 489 | m_triple.Clear(); |
| 490 | // Need to do something about unsetting breakpoints. |
| 491 | |
| 492 | if (executable_sp) |
| 493 | { |
| 494 | FileSpec exec_file_spec = executable_sp->GetFileSpec(); |
| 495 | Error error = ModuleList::GetSharedModule(exec_file_spec, |
| 496 | arch_spec, |
| 497 | NULL, |
| 498 | NULL, |
| 499 | 0, |
| 500 | executable_sp, |
| 501 | NULL, |
| 502 | NULL); |
| 503 | |
| 504 | if (!error.Fail() && executable_sp) |
| 505 | { |
| 506 | SetExecutableModule (executable_sp, true); |
| 507 | return true; |
| 508 | } |
| 509 | else |
| 510 | { |
| 511 | return false; |
| 512 | } |
| 513 | } |
| 514 | else |
| 515 | { |
| 516 | return false; |
| 517 | } |
| 518 | } |
| 519 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 520 | |
| 521 | bool |
| 522 | Target::GetTargetTriple(ConstString &triple) |
| 523 | { |
| 524 | triple.Clear(); |
| 525 | |
| 526 | if (m_triple) |
| 527 | { |
| 528 | triple = m_triple; |
| 529 | } |
| 530 | else |
| 531 | { |
| 532 | Module *exe_module = GetExecutableModule().get(); |
| 533 | if (exe_module) |
| 534 | { |
| 535 | ObjectFile *objfile = exe_module->GetObjectFile(); |
| 536 | if (objfile) |
| 537 | { |
| 538 | objfile->GetTargetTriple(m_triple); |
| 539 | triple = m_triple; |
| 540 | } |
| 541 | } |
| 542 | } |
| 543 | return !triple.IsEmpty(); |
| 544 | } |
| 545 | |
| 546 | void |
| 547 | Target::ModuleAdded (ModuleSP &module_sp) |
| 548 | { |
| 549 | // A module is being added to this target for the first time |
| 550 | ModuleList module_list; |
| 551 | module_list.Append(module_sp); |
| 552 | ModulesDidLoad (module_list); |
| 553 | } |
| 554 | |
| 555 | void |
| 556 | Target::ModuleUpdated (ModuleSP &old_module_sp, ModuleSP &new_module_sp) |
| 557 | { |
| 558 | // A module is being added to this target for the first time |
| 559 | ModuleList module_list; |
| 560 | module_list.Append (old_module_sp); |
| 561 | ModulesDidUnload (module_list); |
| 562 | module_list.Clear (); |
| 563 | module_list.Append (new_module_sp); |
| 564 | ModulesDidLoad (module_list); |
| 565 | } |
| 566 | |
| 567 | void |
| 568 | Target::ModulesDidLoad (ModuleList &module_list) |
| 569 | { |
| 570 | m_breakpoint_list.UpdateBreakpoints (module_list, true); |
| 571 | // TODO: make event data that packages up the module_list |
| 572 | BroadcastEvent (eBroadcastBitModulesLoaded, NULL); |
| 573 | } |
| 574 | |
| 575 | void |
| 576 | Target::ModulesDidUnload (ModuleList &module_list) |
| 577 | { |
| 578 | m_breakpoint_list.UpdateBreakpoints (module_list, false); |
| 579 | // TODO: make event data that packages up the module_list |
| 580 | BroadcastEvent (eBroadcastBitModulesUnloaded, NULL); |
| 581 | } |
| 582 | |
| 583 | size_t |
Greg Clayton | 2cf6e9e | 2010-06-30 23:04:24 +0000 | [diff] [blame] | 584 | Target::ReadMemory (const Address& addr, void *dst, size_t dst_len, Error &error) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 585 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 586 | error.Clear(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 587 | |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 588 | bool process_is_valid = m_process_sp && m_process_sp->IsAlive(); |
| 589 | |
| 590 | Address resolved_addr(addr); |
| 591 | if (!resolved_addr.IsSectionOffset()) |
| 592 | { |
| 593 | if (process_is_valid) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 594 | { |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 595 | m_section_load_list.ResolveLoadAddress (addr.GetOffset(), resolved_addr); |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 596 | } |
| 597 | else |
| 598 | { |
| 599 | m_images.ResolveFileAddress(addr.GetOffset(), resolved_addr); |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | |
| 604 | if (process_is_valid) |
| 605 | { |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 606 | lldb::addr_t load_addr = resolved_addr.GetLoadAddress (this); |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 607 | if (load_addr == LLDB_INVALID_ADDRESS) |
| 608 | { |
| 609 | if (resolved_addr.GetModule() && resolved_addr.GetModule()->GetFileSpec()) |
| 610 | error.SetErrorStringWithFormat("%s[0x%llx] can't be resolved, %s in not currently loaded.\n", |
| 611 | resolved_addr.GetModule()->GetFileSpec().GetFilename().AsCString(), |
| 612 | resolved_addr.GetFileAddress()); |
| 613 | else |
| 614 | error.SetErrorStringWithFormat("0x%llx can't be resolved.\n", resolved_addr.GetFileAddress()); |
| 615 | } |
| 616 | else |
| 617 | { |
| 618 | size_t bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 619 | if (bytes_read != dst_len) |
| 620 | { |
| 621 | if (error.Success()) |
| 622 | { |
| 623 | if (bytes_read == 0) |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 624 | error.SetErrorStringWithFormat("Read memory from 0x%llx failed.\n", load_addr); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 625 | else |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 626 | error.SetErrorStringWithFormat("Only %zu of %zu bytes were read from memory at 0x%llx.\n", bytes_read, dst_len, load_addr); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 627 | } |
| 628 | } |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 629 | if (bytes_read) |
| 630 | return bytes_read; |
| 631 | // If the address is not section offset we have an address that |
| 632 | // doesn't resolve to any address in any currently loaded shared |
| 633 | // libaries and we failed to read memory so there isn't anything |
| 634 | // more we can do. If it is section offset, we might be able to |
| 635 | // read cached memory from the object file. |
| 636 | if (!resolved_addr.IsSectionOffset()) |
| 637 | return 0; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 638 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 639 | } |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 640 | |
| 641 | const Section *section = resolved_addr.GetSection(); |
| 642 | if (section && section->GetModule()) |
| 643 | { |
| 644 | ObjectFile *objfile = section->GetModule()->GetObjectFile(); |
| 645 | return section->ReadSectionDataFromObjectFile (objfile, |
| 646 | resolved_addr.GetOffset(), |
| 647 | dst, |
| 648 | dst_len); |
| 649 | } |
| 650 | return 0; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | |
| 654 | ModuleSP |
| 655 | Target::GetSharedModule |
| 656 | ( |
| 657 | const FileSpec& file_spec, |
| 658 | const ArchSpec& arch, |
| 659 | const UUID *uuid_ptr, |
| 660 | const ConstString *object_name, |
| 661 | off_t object_offset, |
| 662 | Error *error_ptr |
| 663 | ) |
| 664 | { |
| 665 | // Don't pass in the UUID so we can tell if we have a stale value in our list |
| 666 | ModuleSP old_module_sp; // This will get filled in if we have a new version of the library |
| 667 | bool did_create_module = false; |
| 668 | ModuleSP module_sp; |
| 669 | |
| 670 | // If there are image search path entries, try to use them first to acquire a suitable image. |
| 671 | |
| 672 | Error error; |
| 673 | |
| 674 | if (m_image_search_paths.GetSize()) |
| 675 | { |
| 676 | FileSpec transformed_spec; |
| 677 | if (m_image_search_paths.RemapPath (file_spec.GetDirectory(), transformed_spec.GetDirectory())) |
| 678 | { |
| 679 | transformed_spec.GetFilename() = file_spec.GetFilename(); |
| 680 | error = ModuleList::GetSharedModule (transformed_spec, arch, uuid_ptr, object_name, object_offset, module_sp, &old_module_sp, &did_create_module); |
| 681 | } |
| 682 | } |
| 683 | |
| 684 | // If a module hasn't been found yet, use the unmodified path. |
| 685 | |
| 686 | if (!module_sp) |
| 687 | { |
| 688 | error = (ModuleList::GetSharedModule (file_spec, arch, uuid_ptr, object_name, object_offset, module_sp, &old_module_sp, &did_create_module)); |
| 689 | } |
| 690 | |
| 691 | if (module_sp) |
| 692 | { |
| 693 | m_images.Append (module_sp); |
| 694 | if (did_create_module) |
| 695 | { |
| 696 | if (old_module_sp && m_images.GetIndexForModule (old_module_sp.get()) != LLDB_INVALID_INDEX32) |
| 697 | ModuleUpdated(old_module_sp, module_sp); |
| 698 | else |
| 699 | ModuleAdded(module_sp); |
| 700 | } |
| 701 | } |
| 702 | if (error_ptr) |
| 703 | *error_ptr = error; |
| 704 | return module_sp; |
| 705 | } |
| 706 | |
| 707 | |
| 708 | Target * |
| 709 | Target::CalculateTarget () |
| 710 | { |
| 711 | return this; |
| 712 | } |
| 713 | |
| 714 | Process * |
| 715 | Target::CalculateProcess () |
| 716 | { |
| 717 | return NULL; |
| 718 | } |
| 719 | |
| 720 | Thread * |
| 721 | Target::CalculateThread () |
| 722 | { |
| 723 | return NULL; |
| 724 | } |
| 725 | |
| 726 | StackFrame * |
| 727 | Target::CalculateStackFrame () |
| 728 | { |
| 729 | return NULL; |
| 730 | } |
| 731 | |
| 732 | void |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 733 | Target::CalculateExecutionContext (ExecutionContext &exe_ctx) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 734 | { |
| 735 | exe_ctx.target = this; |
| 736 | exe_ctx.process = NULL; // Do NOT fill in process... |
| 737 | exe_ctx.thread = NULL; |
| 738 | exe_ctx.frame = NULL; |
| 739 | } |
| 740 | |
| 741 | PathMappingList & |
| 742 | Target::GetImageSearchPathList () |
| 743 | { |
| 744 | return m_image_search_paths; |
| 745 | } |
| 746 | |
| 747 | void |
| 748 | Target::ImageSearchPathsChanged |
| 749 | ( |
| 750 | const PathMappingList &path_list, |
| 751 | void *baton |
| 752 | ) |
| 753 | { |
| 754 | Target *target = (Target *)baton; |
| 755 | if (target->m_images.GetSize() > 1) |
| 756 | { |
| 757 | ModuleSP exe_module_sp (target->GetExecutableModule()); |
| 758 | if (exe_module_sp) |
| 759 | { |
| 760 | target->m_images.Clear(); |
| 761 | target->SetExecutableModule (exe_module_sp, true); |
| 762 | } |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | ClangASTContext * |
| 767 | Target::GetScratchClangASTContext() |
| 768 | { |
| 769 | return m_scratch_ast_context_ap.get(); |
| 770 | } |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 771 | |
| 772 | lldb::UserSettingsControllerSP |
| 773 | Target::GetSettingsController (bool finish) |
| 774 | { |
| 775 | static lldb::UserSettingsControllerSP g_settings_controller (new SettingsController); |
| 776 | static bool initialized = false; |
| 777 | |
| 778 | if (!initialized) |
| 779 | { |
| 780 | initialized = UserSettingsController::InitializeSettingsController (g_settings_controller, |
| 781 | Target::SettingsController::global_settings_table, |
| 782 | Target::SettingsController::instance_settings_table); |
| 783 | } |
| 784 | |
| 785 | if (finish) |
| 786 | { |
| 787 | UserSettingsController::FinalizeSettingsController (g_settings_controller); |
| 788 | g_settings_controller.reset(); |
| 789 | initialized = false; |
| 790 | } |
| 791 | |
| 792 | return g_settings_controller; |
| 793 | } |
| 794 | |
| 795 | ArchSpec |
| 796 | Target::GetDefaultArchitecture () |
| 797 | { |
| 798 | lldb::UserSettingsControllerSP settings_controller = Target::GetSettingsController(); |
| 799 | lldb::SettableVariableType var_type; |
| 800 | Error err; |
| 801 | StringList result = settings_controller->GetVariable ("target.default-arch", var_type, "[]", err); |
| 802 | |
| 803 | const char *default_name = ""; |
| 804 | if (result.GetSize() == 1 && err.Success()) |
| 805 | default_name = result.GetStringAtIndex (0); |
| 806 | |
| 807 | ArchSpec default_arch (default_name); |
| 808 | return default_arch; |
| 809 | } |
| 810 | |
| 811 | void |
| 812 | Target::SetDefaultArchitecture (ArchSpec new_arch) |
| 813 | { |
| 814 | if (new_arch.IsValid()) |
| 815 | Target::GetSettingsController ()->SetVariable ("target.default-arch", new_arch.AsCString(), |
| 816 | lldb::eVarSetOperationAssign, false, "[]"); |
| 817 | } |
| 818 | |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 819 | Target * |
| 820 | Target::GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, const SymbolContext *sc_ptr) |
| 821 | { |
| 822 | // The target can either exist in the "process" of ExecutionContext, or in |
| 823 | // the "target_sp" member of SymbolContext. This accessor helper function |
| 824 | // will get the target from one of these locations. |
| 825 | |
| 826 | Target *target = NULL; |
| 827 | if (sc_ptr != NULL) |
| 828 | target = sc_ptr->target_sp.get(); |
| 829 | if (target == NULL) |
| 830 | { |
| 831 | if (exe_ctx_ptr != NULL && exe_ctx_ptr->process != NULL) |
| 832 | target = &exe_ctx_ptr->process->GetTarget(); |
| 833 | } |
| 834 | return target; |
| 835 | } |
| 836 | |
| 837 | |
Caroline Tice | 1ebef44 | 2010-09-27 00:30:10 +0000 | [diff] [blame] | 838 | void |
| 839 | Target::UpdateInstanceName () |
| 840 | { |
| 841 | StreamString sstr; |
| 842 | |
| 843 | ModuleSP module_sp = GetExecutableModule(); |
| 844 | if (module_sp) |
| 845 | { |
Greg Clayton | bf6e210 | 2010-10-27 02:06:37 +0000 | [diff] [blame] | 846 | sstr.Printf ("%s_%s", |
| 847 | module_sp->GetFileSpec().GetFilename().AsCString(), |
Caroline Tice | 1ebef44 | 2010-09-27 00:30:10 +0000 | [diff] [blame] | 848 | module_sp->GetArchitecture().AsCString()); |
Greg Clayton | bf6e210 | 2010-10-27 02:06:37 +0000 | [diff] [blame] | 849 | Target::GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(), |
| 850 | sstr.GetData()); |
Caroline Tice | 1ebef44 | 2010-09-27 00:30:10 +0000 | [diff] [blame] | 851 | } |
| 852 | } |
| 853 | |
Sean Callanan | 77e9394 | 2010-10-29 00:29:03 +0000 | [diff] [blame] | 854 | const char * |
| 855 | Target::GetExpressionPrefixContentsAsCString () |
| 856 | { |
| 857 | return m_expr_prefix_contents.c_str(); |
| 858 | } |
| 859 | |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 860 | //-------------------------------------------------------------- |
| 861 | // class Target::SettingsController |
| 862 | //-------------------------------------------------------------- |
| 863 | |
| 864 | Target::SettingsController::SettingsController () : |
| 865 | UserSettingsController ("target", Debugger::GetSettingsController()), |
| 866 | m_default_architecture () |
| 867 | { |
| 868 | m_default_settings.reset (new TargetInstanceSettings (*this, false, |
| 869 | InstanceSettings::GetDefaultName().AsCString())); |
| 870 | } |
| 871 | |
| 872 | Target::SettingsController::~SettingsController () |
| 873 | { |
| 874 | } |
| 875 | |
| 876 | lldb::InstanceSettingsSP |
| 877 | Target::SettingsController::CreateInstanceSettings (const char *instance_name) |
| 878 | { |
| 879 | TargetInstanceSettings *new_settings = new TargetInstanceSettings (*(Target::GetSettingsController().get()), |
| 880 | false, instance_name); |
| 881 | lldb::InstanceSettingsSP new_settings_sp (new_settings); |
| 882 | return new_settings_sp; |
| 883 | } |
| 884 | |
| 885 | const ConstString & |
| 886 | Target::SettingsController::DefArchVarName () |
| 887 | { |
| 888 | static ConstString def_arch_var_name ("default-arch"); |
| 889 | |
| 890 | return def_arch_var_name; |
| 891 | } |
| 892 | |
| 893 | bool |
| 894 | Target::SettingsController::SetGlobalVariable (const ConstString &var_name, |
| 895 | const char *index_value, |
| 896 | const char *value, |
| 897 | const SettingEntry &entry, |
| 898 | const lldb::VarSetOperationType op, |
| 899 | Error&err) |
| 900 | { |
| 901 | if (var_name == DefArchVarName()) |
| 902 | { |
| 903 | ArchSpec tmp_spec (value); |
| 904 | if (tmp_spec.IsValid()) |
| 905 | m_default_architecture = tmp_spec; |
| 906 | else |
| 907 | err.SetErrorStringWithFormat ("'%s' is not a valid architecture.", value); |
| 908 | } |
| 909 | return true; |
| 910 | } |
| 911 | |
| 912 | |
| 913 | bool |
| 914 | Target::SettingsController::GetGlobalVariable (const ConstString &var_name, |
| 915 | StringList &value, |
| 916 | Error &err) |
| 917 | { |
| 918 | if (var_name == DefArchVarName()) |
| 919 | { |
Greg Clayton | bf6e210 | 2010-10-27 02:06:37 +0000 | [diff] [blame] | 920 | // If the arch is invalid (the default), don't show a string for it |
| 921 | if (m_default_architecture.IsValid()) |
| 922 | value.AppendString (m_default_architecture.AsCString()); |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 923 | return true; |
| 924 | } |
| 925 | else |
| 926 | err.SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString()); |
| 927 | |
| 928 | return false; |
| 929 | } |
| 930 | |
| 931 | //-------------------------------------------------------------- |
| 932 | // class TargetInstanceSettings |
| 933 | //-------------------------------------------------------------- |
| 934 | |
| 935 | TargetInstanceSettings::TargetInstanceSettings (UserSettingsController &owner, bool live_instance, |
| 936 | const char *name) : |
| 937 | InstanceSettings (owner, (name == NULL ? InstanceSettings::InvalidName().AsCString() : name), live_instance) |
| 938 | { |
| 939 | // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called |
| 940 | // until the vtables for TargetInstanceSettings are properly set up, i.e. AFTER all the initializers. |
| 941 | // For this reason it has to be called here, rather than in the initializer or in the parent constructor. |
| 942 | // This is true for CreateInstanceName() too. |
| 943 | |
| 944 | if (GetInstanceName () == InstanceSettings::InvalidName()) |
| 945 | { |
| 946 | ChangeInstanceName (std::string (CreateInstanceName().AsCString())); |
| 947 | m_owner.RegisterInstanceSettings (this); |
| 948 | } |
| 949 | |
| 950 | if (live_instance) |
| 951 | { |
| 952 | const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name); |
| 953 | CopyInstanceSettings (pending_settings,false); |
| 954 | //m_owner.RemovePendingSettings (m_instance_name); |
| 955 | } |
| 956 | } |
| 957 | |
| 958 | TargetInstanceSettings::TargetInstanceSettings (const TargetInstanceSettings &rhs) : |
| 959 | InstanceSettings (*(Target::GetSettingsController().get()), CreateInstanceName().AsCString()) |
| 960 | { |
| 961 | if (m_instance_name != InstanceSettings::GetDefaultName()) |
| 962 | { |
| 963 | const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name); |
| 964 | CopyInstanceSettings (pending_settings,false); |
| 965 | //m_owner.RemovePendingSettings (m_instance_name); |
| 966 | } |
| 967 | } |
| 968 | |
| 969 | TargetInstanceSettings::~TargetInstanceSettings () |
| 970 | { |
| 971 | } |
| 972 | |
| 973 | TargetInstanceSettings& |
| 974 | TargetInstanceSettings::operator= (const TargetInstanceSettings &rhs) |
| 975 | { |
| 976 | if (this != &rhs) |
| 977 | { |
| 978 | } |
| 979 | |
| 980 | return *this; |
| 981 | } |
| 982 | |
Sean Callanan | 77e9394 | 2010-10-29 00:29:03 +0000 | [diff] [blame] | 983 | #define EXPR_PREFIX_STRING "expr-prefix" |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 984 | |
| 985 | void |
| 986 | TargetInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name, |
| 987 | const char *index_value, |
| 988 | const char *value, |
| 989 | const ConstString &instance_name, |
| 990 | const SettingEntry &entry, |
| 991 | lldb::VarSetOperationType op, |
| 992 | Error &err, |
| 993 | bool pending) |
| 994 | { |
Sean Callanan | 77e9394 | 2010-10-29 00:29:03 +0000 | [diff] [blame] | 995 | static ConstString expr_prefix_str (EXPR_PREFIX_STRING); |
| 996 | |
| 997 | if (var_name == expr_prefix_str) |
| 998 | { |
| 999 | switch (op) |
| 1000 | { |
| 1001 | default: |
| 1002 | err.SetErrorToGenericError (); |
| 1003 | err.SetErrorString ("Unrecognized operation. Cannot update value.\n"); |
| 1004 | return; |
| 1005 | case lldb::eVarSetOperationAssign: |
| 1006 | { |
| 1007 | FileSpec file_spec(value, true); |
| 1008 | |
| 1009 | if (!file_spec.Exists()) |
| 1010 | { |
| 1011 | err.SetErrorToGenericError (); |
| 1012 | err.SetErrorStringWithFormat ("%s does not exist.\n", value); |
| 1013 | return; |
| 1014 | } |
| 1015 | |
| 1016 | DataBufferMemoryMap buf; |
| 1017 | |
| 1018 | if (!buf.MemoryMapFromFileSpec(&file_spec) && |
| 1019 | buf.GetError().Fail()) |
| 1020 | { |
| 1021 | err.SetErrorToGenericError (); |
| 1022 | err.SetErrorStringWithFormat ("Couldn't read from %s: %s\n", value, buf.GetError().AsCString()); |
| 1023 | return; |
| 1024 | } |
| 1025 | |
| 1026 | m_expr_prefix_path = value; |
| 1027 | m_expr_prefix_contents.assign(reinterpret_cast<const char *>(buf.GetBytes()), buf.GetByteSize()); |
| 1028 | } |
| 1029 | return; |
| 1030 | case lldb::eVarSetOperationAppend: |
| 1031 | err.SetErrorToGenericError (); |
| 1032 | err.SetErrorString ("Cannot append to a path.\n"); |
| 1033 | return; |
| 1034 | case lldb::eVarSetOperationClear: |
| 1035 | m_expr_prefix_path.clear (); |
| 1036 | m_expr_prefix_contents.clear (); |
| 1037 | return; |
| 1038 | } |
| 1039 | } |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | void |
| 1043 | TargetInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings, |
Sean Callanan | 77e9394 | 2010-10-29 00:29:03 +0000 | [diff] [blame] | 1044 | bool pending) |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 1045 | { |
Sean Callanan | 77e9394 | 2010-10-29 00:29:03 +0000 | [diff] [blame] | 1046 | TargetInstanceSettings *new_settings_ptr = static_cast <TargetInstanceSettings *> (new_settings.get()); |
| 1047 | |
| 1048 | if (!new_settings_ptr) |
| 1049 | return; |
| 1050 | |
| 1051 | m_expr_prefix_path = new_settings_ptr->m_expr_prefix_path; |
| 1052 | m_expr_prefix_contents = new_settings_ptr->m_expr_prefix_contents; |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 1053 | } |
| 1054 | |
Caroline Tice | bcb5b45 | 2010-09-20 21:37:42 +0000 | [diff] [blame] | 1055 | bool |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 1056 | TargetInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry, |
| 1057 | const ConstString &var_name, |
| 1058 | StringList &value, |
Caroline Tice | bcb5b45 | 2010-09-20 21:37:42 +0000 | [diff] [blame] | 1059 | Error *err) |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 1060 | { |
Sean Callanan | 77e9394 | 2010-10-29 00:29:03 +0000 | [diff] [blame] | 1061 | static ConstString expr_prefix_str (EXPR_PREFIX_STRING); |
| 1062 | |
| 1063 | if (var_name == expr_prefix_str) |
| 1064 | { |
| 1065 | value.AppendString (m_expr_prefix_path.c_str(), m_expr_prefix_path.size()); |
| 1066 | } |
| 1067 | else |
| 1068 | { |
| 1069 | if (err) |
| 1070 | err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString()); |
| 1071 | return false; |
| 1072 | } |
| 1073 | |
| 1074 | return true; |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | const ConstString |
| 1078 | TargetInstanceSettings::CreateInstanceName () |
| 1079 | { |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 1080 | StreamString sstr; |
Caroline Tice | 1ebef44 | 2010-09-27 00:30:10 +0000 | [diff] [blame] | 1081 | static int instance_count = 1; |
| 1082 | |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 1083 | sstr.Printf ("target_%d", instance_count); |
| 1084 | ++instance_count; |
| 1085 | |
| 1086 | const ConstString ret_val (sstr.GetData()); |
| 1087 | return ret_val; |
| 1088 | } |
| 1089 | |
| 1090 | //-------------------------------------------------- |
| 1091 | // Target::SettingsController Variable Tables |
| 1092 | //-------------------------------------------------- |
| 1093 | |
| 1094 | SettingEntry |
| 1095 | Target::SettingsController::global_settings_table[] = |
| 1096 | { |
Sean Callanan | 77e9394 | 2010-10-29 00:29:03 +0000 | [diff] [blame] | 1097 | //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"}, |
| 1098 | { "default-arch", eSetVarTypeString, NULL, NULL, false, false, "Default architecture to choose, when there's a choice." }, |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 1099 | { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL } |
| 1100 | }; |
| 1101 | |
| 1102 | SettingEntry |
| 1103 | Target::SettingsController::instance_settings_table[] = |
| 1104 | { |
Sean Callanan | 77e9394 | 2010-10-29 00:29:03 +0000 | [diff] [blame] | 1105 | //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"}, |
| 1106 | { EXPR_PREFIX_STRING, eSetVarTypeString, NULL, NULL, false, false, "Path to a file containing expressions to be prepended to all expressions." }, |
Caroline Tice | 5bc8c97 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 1107 | { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL } |
| 1108 | }; |