1 //===-- SBValue.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/API/SBValue.h" 11 12 #include "lldb/API/SBDeclaration.h" 13 #include "lldb/API/SBStream.h" 14 #include "lldb/API/SBTypeFilter.h" 15 #include "lldb/API/SBTypeFormat.h" 16 #include "lldb/API/SBTypeSummary.h" 17 #include "lldb/API/SBTypeSynthetic.h" 18 19 #include "lldb/Breakpoint/Watchpoint.h" 20 #include "lldb/Core/Module.h" 21 #include "lldb/Core/Section.h" 22 #include "lldb/Core/StreamFile.h" 23 #include "lldb/Core/Value.h" 24 #include "lldb/Core/ValueObject.h" 25 #include "lldb/Core/ValueObjectConstResult.h" 26 #include "lldb/DataFormatters/DataVisualization.h" 27 #include "lldb/Symbol/Block.h" 28 #include "lldb/Symbol/Declaration.h" 29 #include "lldb/Symbol/ObjectFile.h" 30 #include "lldb/Symbol/Type.h" 31 #include "lldb/Symbol/Variable.h" 32 #include "lldb/Symbol/VariableList.h" 33 #include "lldb/Target/ExecutionContext.h" 34 #include "lldb/Target/Process.h" 35 #include "lldb/Target/StackFrame.h" 36 #include "lldb/Target/Target.h" 37 #include "lldb/Target/Thread.h" 38 #include "lldb/Utility/DataExtractor.h" 39 #include "lldb/Utility/Log.h" 40 #include "lldb/Utility/Scalar.h" 41 #include "lldb/Utility/Stream.h" 42 43 #include "lldb/API/SBDebugger.h" 44 #include "lldb/API/SBExpressionOptions.h" 45 #include "lldb/API/SBFrame.h" 46 #include "lldb/API/SBProcess.h" 47 #include "lldb/API/SBTarget.h" 48 #include "lldb/API/SBThread.h" 49 50 using namespace lldb; 51 using namespace lldb_private; 52 53 class ValueImpl { 54 public: 55 ValueImpl() {} 56 57 ValueImpl(lldb::ValueObjectSP in_valobj_sp, 58 lldb::DynamicValueType use_dynamic, bool use_synthetic, 59 const char *name = NULL) 60 : m_valobj_sp(), m_use_dynamic(use_dynamic), 61 m_use_synthetic(use_synthetic), m_name(name) { 62 if (in_valobj_sp) { 63 if ((m_valobj_sp = in_valobj_sp->GetQualifiedRepresentationIfAvailable( 64 lldb::eNoDynamicValues, false))) { 65 if (!m_name.IsEmpty()) 66 m_valobj_sp->SetName(m_name); 67 } 68 } 69 } 70 71 ValueImpl(const ValueImpl &rhs) 72 : m_valobj_sp(rhs.m_valobj_sp), m_use_dynamic(rhs.m_use_dynamic), 73 m_use_synthetic(rhs.m_use_synthetic), m_name(rhs.m_name) {} 74 75 ValueImpl &operator=(const ValueImpl &rhs) { 76 if (this != &rhs) { 77 m_valobj_sp = rhs.m_valobj_sp; 78 m_use_dynamic = rhs.m_use_dynamic; 79 m_use_synthetic = rhs.m_use_synthetic; 80 m_name = rhs.m_name; 81 } 82 return *this; 83 } 84 85 bool IsValid() { 86 if (m_valobj_sp.get() == NULL) 87 return false; 88 else { 89 // FIXME: This check is necessary but not sufficient. We for sure don't 90 // want to touch SBValues whose owning 91 // targets have gone away. This check is a little weak in that it 92 // enforces that restriction when you call IsValid, but since IsValid 93 // doesn't lock the target, you have no guarantee that the SBValue won't 94 // go invalid after you call this... Also, an SBValue could depend on 95 // data from one of the modules in the target, and those could go away 96 // independently of the target, for instance if a module is unloaded. 97 // But right now, neither SBValues nor ValueObjects know which modules 98 // they depend on. So I have no good way to make that check without 99 // tracking that in all the ValueObject subclasses. 100 TargetSP target_sp = m_valobj_sp->GetTargetSP(); 101 return target_sp && target_sp->IsValid(); 102 } 103 } 104 105 lldb::ValueObjectSP GetRootSP() { return m_valobj_sp; } 106 107 lldb::ValueObjectSP GetSP(Process::StopLocker &stop_locker, 108 std::unique_lock<std::recursive_mutex> &lock, 109 Status &error) { 110 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 111 if (!m_valobj_sp) { 112 error.SetErrorString("invalid value object"); 113 return m_valobj_sp; 114 } 115 116 lldb::ValueObjectSP value_sp = m_valobj_sp; 117 118 Target *target = value_sp->GetTargetSP().get(); 119 if (!target) 120 return ValueObjectSP(); 121 122 lock = std::unique_lock<std::recursive_mutex>(target->GetAPIMutex()); 123 124 ProcessSP process_sp(value_sp->GetProcessSP()); 125 if (process_sp && !stop_locker.TryLock(&process_sp->GetRunLock())) { 126 // We don't allow people to play around with ValueObject if the process 127 // is running. If you want to look at values, pause the process, then 128 // look. 129 if (log) 130 log->Printf("SBValue(%p)::GetSP() => error: process is running", 131 static_cast<void *>(value_sp.get())); 132 error.SetErrorString("process must be stopped."); 133 return ValueObjectSP(); 134 } 135 136 if (m_use_dynamic != eNoDynamicValues) { 137 ValueObjectSP dynamic_sp = value_sp->GetDynamicValue(m_use_dynamic); 138 if (dynamic_sp) 139 value_sp = dynamic_sp; 140 } 141 142 if (m_use_synthetic) { 143 ValueObjectSP synthetic_sp = value_sp->GetSyntheticValue(m_use_synthetic); 144 if (synthetic_sp) 145 value_sp = synthetic_sp; 146 } 147 148 if (!value_sp) 149 error.SetErrorString("invalid value object"); 150 if (!m_name.IsEmpty()) 151 value_sp->SetName(m_name); 152 153 return value_sp; 154 } 155 156 void SetUseDynamic(lldb::DynamicValueType use_dynamic) { 157 m_use_dynamic = use_dynamic; 158 } 159 160 void SetUseSynthetic(bool use_synthetic) { m_use_synthetic = use_synthetic; } 161 162 lldb::DynamicValueType GetUseDynamic() { return m_use_dynamic; } 163 164 bool GetUseSynthetic() { return m_use_synthetic; } 165 166 // All the derived values that we would make from the m_valobj_sp will share 167 // the ExecutionContext with m_valobj_sp, so we don't need to do the 168 // calculations in GetSP to return the Target, Process, Thread or Frame. It 169 // is convenient to provide simple accessors for these, which I do here. 170 TargetSP GetTargetSP() { 171 if (m_valobj_sp) 172 return m_valobj_sp->GetTargetSP(); 173 else 174 return TargetSP(); 175 } 176 177 ProcessSP GetProcessSP() { 178 if (m_valobj_sp) 179 return m_valobj_sp->GetProcessSP(); 180 else 181 return ProcessSP(); 182 } 183 184 ThreadSP GetThreadSP() { 185 if (m_valobj_sp) 186 return m_valobj_sp->GetThreadSP(); 187 else 188 return ThreadSP(); 189 } 190 191 StackFrameSP GetFrameSP() { 192 if (m_valobj_sp) 193 return m_valobj_sp->GetFrameSP(); 194 else 195 return StackFrameSP(); 196 } 197 198 private: 199 lldb::ValueObjectSP m_valobj_sp; 200 lldb::DynamicValueType m_use_dynamic; 201 bool m_use_synthetic; 202 ConstString m_name; 203 }; 204 205 class ValueLocker { 206 public: 207 ValueLocker() {} 208 209 ValueObjectSP GetLockedSP(ValueImpl &in_value) { 210 return in_value.GetSP(m_stop_locker, m_lock, m_lock_error); 211 } 212 213 Status &GetError() { return m_lock_error; } 214 215 private: 216 Process::StopLocker m_stop_locker; 217 std::unique_lock<std::recursive_mutex> m_lock; 218 Status m_lock_error; 219 }; 220 221 SBValue::SBValue() : m_opaque_sp() {} 222 223 SBValue::SBValue(const lldb::ValueObjectSP &value_sp) { SetSP(value_sp); } 224 225 SBValue::SBValue(const SBValue &rhs) { SetSP(rhs.m_opaque_sp); } 226 227 SBValue &SBValue::operator=(const SBValue &rhs) { 228 if (this != &rhs) { 229 SetSP(rhs.m_opaque_sp); 230 } 231 return *this; 232 } 233 234 SBValue::~SBValue() {} 235 236 bool SBValue::IsValid() { 237 // If this function ever changes to anything that does more than just check 238 // if the opaque shared pointer is non NULL, then we need to update all "if 239 // (m_opaque_sp)" code in this file. 240 return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid() && 241 m_opaque_sp->GetRootSP().get() != NULL; 242 } 243 244 void SBValue::Clear() { m_opaque_sp.reset(); } 245 246 SBError SBValue::GetError() { 247 SBError sb_error; 248 249 ValueLocker locker; 250 lldb::ValueObjectSP value_sp(GetSP(locker)); 251 if (value_sp) 252 sb_error.SetError(value_sp->GetError()); 253 else 254 sb_error.SetErrorStringWithFormat("error: %s", 255 locker.GetError().AsCString()); 256 257 return sb_error; 258 } 259 260 user_id_t SBValue::GetID() { 261 ValueLocker locker; 262 lldb::ValueObjectSP value_sp(GetSP(locker)); 263 if (value_sp) 264 return value_sp->GetID(); 265 return LLDB_INVALID_UID; 266 } 267 268 const char *SBValue::GetName() { 269 const char *name = NULL; 270 ValueLocker locker; 271 lldb::ValueObjectSP value_sp(GetSP(locker)); 272 if (value_sp) 273 name = value_sp->GetName().GetCString(); 274 275 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 276 if (log) { 277 if (name) 278 log->Printf("SBValue(%p)::GetName () => \"%s\"", 279 static_cast<void *>(value_sp.get()), name); 280 else 281 log->Printf("SBValue(%p)::GetName () => NULL", 282 static_cast<void *>(value_sp.get())); 283 } 284 285 return name; 286 } 287 288 const char *SBValue::GetTypeName() { 289 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 290 const char *name = NULL; 291 ValueLocker locker; 292 lldb::ValueObjectSP value_sp(GetSP(locker)); 293 if (value_sp) { 294 name = value_sp->GetQualifiedTypeName().GetCString(); 295 } 296 297 if (log) { 298 if (name) 299 log->Printf("SBValue(%p)::GetTypeName () => \"%s\"", 300 static_cast<void *>(value_sp.get()), name); 301 else 302 log->Printf("SBValue(%p)::GetTypeName () => NULL", 303 static_cast<void *>(value_sp.get())); 304 } 305 306 return name; 307 } 308 309 const char *SBValue::GetDisplayTypeName() { 310 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 311 const char *name = NULL; 312 ValueLocker locker; 313 lldb::ValueObjectSP value_sp(GetSP(locker)); 314 if (value_sp) { 315 name = value_sp->GetDisplayTypeName().GetCString(); 316 } 317 318 if (log) { 319 if (name) 320 log->Printf("SBValue(%p)::GetTypeName () => \"%s\"", 321 static_cast<void *>(value_sp.get()), name); 322 else 323 log->Printf("SBValue(%p)::GetTypeName () => NULL", 324 static_cast<void *>(value_sp.get())); 325 } 326 327 return name; 328 } 329 330 size_t SBValue::GetByteSize() { 331 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 332 size_t result = 0; 333 334 ValueLocker locker; 335 lldb::ValueObjectSP value_sp(GetSP(locker)); 336 if (value_sp) { 337 result = value_sp->GetByteSize(); 338 } 339 340 if (log) 341 log->Printf("SBValue(%p)::GetByteSize () => %" PRIu64, 342 static_cast<void *>(value_sp.get()), 343 static_cast<uint64_t>(result)); 344 345 return result; 346 } 347 348 bool SBValue::IsInScope() { 349 bool result = false; 350 351 ValueLocker locker; 352 lldb::ValueObjectSP value_sp(GetSP(locker)); 353 if (value_sp) { 354 result = value_sp->IsInScope(); 355 } 356 357 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 358 if (log) 359 log->Printf("SBValue(%p)::IsInScope () => %i", 360 static_cast<void *>(value_sp.get()), result); 361 362 return result; 363 } 364 365 const char *SBValue::GetValue() { 366 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 367 368 const char *cstr = NULL; 369 ValueLocker locker; 370 lldb::ValueObjectSP value_sp(GetSP(locker)); 371 if (value_sp) { 372 cstr = value_sp->GetValueAsCString(); 373 } 374 if (log) { 375 if (cstr) 376 log->Printf("SBValue(%p)::GetValue() => \"%s\"", 377 static_cast<void *>(value_sp.get()), cstr); 378 else 379 log->Printf("SBValue(%p)::GetValue() => NULL", 380 static_cast<void *>(value_sp.get())); 381 } 382 383 return cstr; 384 } 385 386 ValueType SBValue::GetValueType() { 387 ValueType result = eValueTypeInvalid; 388 ValueLocker locker; 389 lldb::ValueObjectSP value_sp(GetSP(locker)); 390 if (value_sp) 391 result = value_sp->GetValueType(); 392 393 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 394 if (log) { 395 switch (result) { 396 case eValueTypeInvalid: 397 log->Printf("SBValue(%p)::GetValueType () => eValueTypeInvalid", 398 static_cast<void *>(value_sp.get())); 399 break; 400 case eValueTypeVariableGlobal: 401 log->Printf("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal", 402 static_cast<void *>(value_sp.get())); 403 break; 404 case eValueTypeVariableStatic: 405 log->Printf("SBValue(%p)::GetValueType () => eValueTypeVariableStatic", 406 static_cast<void *>(value_sp.get())); 407 break; 408 case eValueTypeVariableArgument: 409 log->Printf("SBValue(%p)::GetValueType () => eValueTypeVariableArgument", 410 static_cast<void *>(value_sp.get())); 411 break; 412 case eValueTypeVariableLocal: 413 log->Printf("SBValue(%p)::GetValueType () => eValueTypeVariableLocal", 414 static_cast<void *>(value_sp.get())); 415 break; 416 case eValueTypeRegister: 417 log->Printf("SBValue(%p)::GetValueType () => eValueTypeRegister", 418 static_cast<void *>(value_sp.get())); 419 break; 420 case eValueTypeRegisterSet: 421 log->Printf("SBValue(%p)::GetValueType () => eValueTypeRegisterSet", 422 static_cast<void *>(value_sp.get())); 423 break; 424 case eValueTypeConstResult: 425 log->Printf("SBValue(%p)::GetValueType () => eValueTypeConstResult", 426 static_cast<void *>(value_sp.get())); 427 break; 428 case eValueTypeVariableThreadLocal: 429 log->Printf( 430 "SBValue(%p)::GetValueType () => eValueTypeVariableThreadLocal", 431 static_cast<void *>(value_sp.get())); 432 break; 433 } 434 } 435 return result; 436 } 437 438 const char *SBValue::GetObjectDescription() { 439 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 440 const char *cstr = NULL; 441 ValueLocker locker; 442 lldb::ValueObjectSP value_sp(GetSP(locker)); 443 if (value_sp) { 444 cstr = value_sp->GetObjectDescription(); 445 } 446 if (log) { 447 if (cstr) 448 log->Printf("SBValue(%p)::GetObjectDescription() => \"%s\"", 449 static_cast<void *>(value_sp.get()), cstr); 450 else 451 log->Printf("SBValue(%p)::GetObjectDescription() => NULL", 452 static_cast<void *>(value_sp.get())); 453 } 454 return cstr; 455 } 456 457 const char *SBValue::GetTypeValidatorResult() { 458 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 459 const char *cstr = NULL; 460 ValueLocker locker; 461 lldb::ValueObjectSP value_sp(GetSP(locker)); 462 if (value_sp) { 463 const auto &validation(value_sp->GetValidationStatus()); 464 if (TypeValidatorResult::Failure == validation.first) { 465 if (validation.second.empty()) 466 cstr = "unknown error"; 467 else 468 cstr = validation.second.c_str(); 469 } 470 } 471 if (log) { 472 if (cstr) 473 log->Printf("SBValue(%p)::GetTypeValidatorResult() => \"%s\"", 474 static_cast<void *>(value_sp.get()), cstr); 475 else 476 log->Printf("SBValue(%p)::GetTypeValidatorResult() => NULL", 477 static_cast<void *>(value_sp.get())); 478 } 479 return cstr; 480 } 481 482 SBType SBValue::GetType() { 483 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 484 SBType sb_type; 485 ValueLocker locker; 486 lldb::ValueObjectSP value_sp(GetSP(locker)); 487 TypeImplSP type_sp; 488 if (value_sp) { 489 type_sp.reset(new TypeImpl(value_sp->GetTypeImpl())); 490 sb_type.SetSP(type_sp); 491 } 492 if (log) { 493 if (type_sp) 494 log->Printf("SBValue(%p)::GetType => SBType(%p)", 495 static_cast<void *>(value_sp.get()), 496 static_cast<void *>(type_sp.get())); 497 else 498 log->Printf("SBValue(%p)::GetType => NULL", 499 static_cast<void *>(value_sp.get())); 500 } 501 return sb_type; 502 } 503 504 bool SBValue::GetValueDidChange() { 505 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 506 bool result = false; 507 ValueLocker locker; 508 lldb::ValueObjectSP value_sp(GetSP(locker)); 509 if (value_sp) { 510 if (value_sp->UpdateValueIfNeeded(false)) 511 result = value_sp->GetValueDidChange(); 512 } 513 if (log) 514 log->Printf("SBValue(%p)::GetValueDidChange() => %i", 515 static_cast<void *>(value_sp.get()), result); 516 517 return result; 518 } 519 520 const char *SBValue::GetSummary() { 521 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 522 const char *cstr = NULL; 523 ValueLocker locker; 524 lldb::ValueObjectSP value_sp(GetSP(locker)); 525 if (value_sp) { 526 cstr = value_sp->GetSummaryAsCString(); 527 } 528 if (log) { 529 if (cstr) 530 log->Printf("SBValue(%p)::GetSummary() => \"%s\"", 531 static_cast<void *>(value_sp.get()), cstr); 532 else 533 log->Printf("SBValue(%p)::GetSummary() => NULL", 534 static_cast<void *>(value_sp.get())); 535 } 536 return cstr; 537 } 538 539 const char *SBValue::GetSummary(lldb::SBStream &stream, 540 lldb::SBTypeSummaryOptions &options) { 541 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 542 ValueLocker locker; 543 lldb::ValueObjectSP value_sp(GetSP(locker)); 544 if (value_sp) { 545 std::string buffer; 546 if (value_sp->GetSummaryAsCString(buffer, options.ref()) && !buffer.empty()) 547 stream.Printf("%s", buffer.c_str()); 548 } 549 const char *cstr = stream.GetData(); 550 if (log) { 551 if (cstr) 552 log->Printf("SBValue(%p)::GetSummary() => \"%s\"", 553 static_cast<void *>(value_sp.get()), cstr); 554 else 555 log->Printf("SBValue(%p)::GetSummary() => NULL", 556 static_cast<void *>(value_sp.get())); 557 } 558 return cstr; 559 } 560 561 const char *SBValue::GetLocation() { 562 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 563 const char *cstr = NULL; 564 ValueLocker locker; 565 lldb::ValueObjectSP value_sp(GetSP(locker)); 566 if (value_sp) { 567 cstr = value_sp->GetLocationAsCString(); 568 } 569 if (log) { 570 if (cstr) 571 log->Printf("SBValue(%p)::GetLocation() => \"%s\"", 572 static_cast<void *>(value_sp.get()), cstr); 573 else 574 log->Printf("SBValue(%p)::GetLocation() => NULL", 575 static_cast<void *>(value_sp.get())); 576 } 577 return cstr; 578 } 579 580 // Deprecated - use the one that takes an lldb::SBError 581 bool SBValue::SetValueFromCString(const char *value_str) { 582 lldb::SBError dummy; 583 return SetValueFromCString(value_str, dummy); 584 } 585 586 bool SBValue::SetValueFromCString(const char *value_str, lldb::SBError &error) { 587 bool success = false; 588 ValueLocker locker; 589 lldb::ValueObjectSP value_sp(GetSP(locker)); 590 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 591 if (value_sp) { 592 success = value_sp->SetValueFromCString(value_str, error.ref()); 593 } else 594 error.SetErrorStringWithFormat("Could not get value: %s", 595 locker.GetError().AsCString()); 596 597 if (log) 598 log->Printf("SBValue(%p)::SetValueFromCString(\"%s\") => %i", 599 static_cast<void *>(value_sp.get()), value_str, success); 600 601 return success; 602 } 603 604 lldb::SBTypeFormat SBValue::GetTypeFormat() { 605 lldb::SBTypeFormat format; 606 ValueLocker locker; 607 lldb::ValueObjectSP value_sp(GetSP(locker)); 608 if (value_sp) { 609 if (value_sp->UpdateValueIfNeeded(true)) { 610 lldb::TypeFormatImplSP format_sp = value_sp->GetValueFormat(); 611 if (format_sp) 612 format.SetSP(format_sp); 613 } 614 } 615 return format; 616 } 617 618 lldb::SBTypeSummary SBValue::GetTypeSummary() { 619 lldb::SBTypeSummary summary; 620 ValueLocker locker; 621 lldb::ValueObjectSP value_sp(GetSP(locker)); 622 if (value_sp) { 623 if (value_sp->UpdateValueIfNeeded(true)) { 624 lldb::TypeSummaryImplSP summary_sp = value_sp->GetSummaryFormat(); 625 if (summary_sp) 626 summary.SetSP(summary_sp); 627 } 628 } 629 return summary; 630 } 631 632 lldb::SBTypeFilter SBValue::GetTypeFilter() { 633 lldb::SBTypeFilter filter; 634 ValueLocker locker; 635 lldb::ValueObjectSP value_sp(GetSP(locker)); 636 if (value_sp) { 637 if (value_sp->UpdateValueIfNeeded(true)) { 638 lldb::SyntheticChildrenSP synthetic_sp = value_sp->GetSyntheticChildren(); 639 640 if (synthetic_sp && !synthetic_sp->IsScripted()) { 641 TypeFilterImplSP filter_sp = 642 std::static_pointer_cast<TypeFilterImpl>(synthetic_sp); 643 filter.SetSP(filter_sp); 644 } 645 } 646 } 647 return filter; 648 } 649 650 #ifndef LLDB_DISABLE_PYTHON 651 lldb::SBTypeSynthetic SBValue::GetTypeSynthetic() { 652 lldb::SBTypeSynthetic synthetic; 653 ValueLocker locker; 654 lldb::ValueObjectSP value_sp(GetSP(locker)); 655 if (value_sp) { 656 if (value_sp->UpdateValueIfNeeded(true)) { 657 lldb::SyntheticChildrenSP children_sp = value_sp->GetSyntheticChildren(); 658 659 if (children_sp && children_sp->IsScripted()) { 660 ScriptedSyntheticChildrenSP synth_sp = 661 std::static_pointer_cast<ScriptedSyntheticChildren>(children_sp); 662 synthetic.SetSP(synth_sp); 663 } 664 } 665 } 666 return synthetic; 667 } 668 #endif 669 670 lldb::SBValue SBValue::CreateChildAtOffset(const char *name, uint32_t offset, 671 SBType type) { 672 lldb::SBValue sb_value; 673 ValueLocker locker; 674 lldb::ValueObjectSP value_sp(GetSP(locker)); 675 lldb::ValueObjectSP new_value_sp; 676 if (value_sp) { 677 TypeImplSP type_sp(type.GetSP()); 678 if (type.IsValid()) { 679 sb_value.SetSP(value_sp->GetSyntheticChildAtOffset( 680 offset, type_sp->GetCompilerType(false), true), 681 GetPreferDynamicValue(), GetPreferSyntheticValue(), name); 682 } 683 } 684 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 685 if (log) { 686 if (new_value_sp) 687 log->Printf("SBValue(%p)::CreateChildAtOffset => \"%s\"", 688 static_cast<void *>(value_sp.get()), 689 new_value_sp->GetName().AsCString()); 690 else 691 log->Printf("SBValue(%p)::CreateChildAtOffset => NULL", 692 static_cast<void *>(value_sp.get())); 693 } 694 return sb_value; 695 } 696 697 lldb::SBValue SBValue::Cast(SBType type) { 698 lldb::SBValue sb_value; 699 ValueLocker locker; 700 lldb::ValueObjectSP value_sp(GetSP(locker)); 701 TypeImplSP type_sp(type.GetSP()); 702 if (value_sp && type_sp) 703 sb_value.SetSP(value_sp->Cast(type_sp->GetCompilerType(false)), 704 GetPreferDynamicValue(), GetPreferSyntheticValue()); 705 return sb_value; 706 } 707 708 lldb::SBValue SBValue::CreateValueFromExpression(const char *name, 709 const char *expression) { 710 SBExpressionOptions options; 711 options.ref().SetKeepInMemory(true); 712 return CreateValueFromExpression(name, expression, options); 713 } 714 715 lldb::SBValue SBValue::CreateValueFromExpression(const char *name, 716 const char *expression, 717 SBExpressionOptions &options) { 718 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 719 lldb::SBValue sb_value; 720 ValueLocker locker; 721 lldb::ValueObjectSP value_sp(GetSP(locker)); 722 lldb::ValueObjectSP new_value_sp; 723 if (value_sp) { 724 ExecutionContext exe_ctx(value_sp->GetExecutionContextRef()); 725 new_value_sp = ValueObject::CreateValueObjectFromExpression( 726 name, expression, exe_ctx, options.ref()); 727 if (new_value_sp) 728 new_value_sp->SetName(ConstString(name)); 729 } 730 sb_value.SetSP(new_value_sp); 731 if (log) { 732 if (new_value_sp) 733 log->Printf("SBValue(%p)::CreateValueFromExpression(name=\"%s\", " 734 "expression=\"%s\") => SBValue (%p)", 735 static_cast<void *>(value_sp.get()), name, expression, 736 static_cast<void *>(new_value_sp.get())); 737 else 738 log->Printf("SBValue(%p)::CreateValueFromExpression(name=\"%s\", " 739 "expression=\"%s\") => NULL", 740 static_cast<void *>(value_sp.get()), name, expression); 741 } 742 return sb_value; 743 } 744 745 lldb::SBValue SBValue::CreateValueFromAddress(const char *name, 746 lldb::addr_t address, 747 SBType sb_type) { 748 lldb::SBValue sb_value; 749 ValueLocker locker; 750 lldb::ValueObjectSP value_sp(GetSP(locker)); 751 lldb::ValueObjectSP new_value_sp; 752 lldb::TypeImplSP type_impl_sp(sb_type.GetSP()); 753 if (value_sp && type_impl_sp) { 754 CompilerType ast_type(type_impl_sp->GetCompilerType(true)); 755 ExecutionContext exe_ctx(value_sp->GetExecutionContextRef()); 756 new_value_sp = ValueObject::CreateValueObjectFromAddress(name, address, 757 exe_ctx, ast_type); 758 } 759 sb_value.SetSP(new_value_sp); 760 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 761 if (log) { 762 if (new_value_sp) 763 log->Printf("SBValue(%p)::CreateValueFromAddress => \"%s\"", 764 static_cast<void *>(value_sp.get()), 765 new_value_sp->GetName().AsCString()); 766 else 767 log->Printf("SBValue(%p)::CreateValueFromAddress => NULL", 768 static_cast<void *>(value_sp.get())); 769 } 770 return sb_value; 771 } 772 773 lldb::SBValue SBValue::CreateValueFromData(const char *name, SBData data, 774 SBType sb_type) { 775 lldb::SBValue sb_value; 776 lldb::ValueObjectSP new_value_sp; 777 ValueLocker locker; 778 lldb::ValueObjectSP value_sp(GetSP(locker)); 779 lldb::TypeImplSP type_impl_sp(sb_type.GetSP()); 780 if (value_sp && type_impl_sp) { 781 ExecutionContext exe_ctx(value_sp->GetExecutionContextRef()); 782 new_value_sp = ValueObject::CreateValueObjectFromData( 783 name, **data, exe_ctx, type_impl_sp->GetCompilerType(true)); 784 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad); 785 } 786 sb_value.SetSP(new_value_sp); 787 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 788 if (log) { 789 if (new_value_sp) 790 log->Printf("SBValue(%p)::CreateValueFromData => \"%s\"", 791 static_cast<void *>(value_sp.get()), 792 new_value_sp->GetName().AsCString()); 793 else 794 log->Printf("SBValue(%p)::CreateValueFromData => NULL", 795 static_cast<void *>(value_sp.get())); 796 } 797 return sb_value; 798 } 799 800 SBValue SBValue::GetChildAtIndex(uint32_t idx) { 801 const bool can_create_synthetic = false; 802 lldb::DynamicValueType use_dynamic = eNoDynamicValues; 803 TargetSP target_sp; 804 if (m_opaque_sp) 805 target_sp = m_opaque_sp->GetTargetSP(); 806 807 if (target_sp) 808 use_dynamic = target_sp->GetPreferDynamicValue(); 809 810 return GetChildAtIndex(idx, use_dynamic, can_create_synthetic); 811 } 812 813 SBValue SBValue::GetChildAtIndex(uint32_t idx, 814 lldb::DynamicValueType use_dynamic, 815 bool can_create_synthetic) { 816 lldb::ValueObjectSP child_sp; 817 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 818 819 ValueLocker locker; 820 lldb::ValueObjectSP value_sp(GetSP(locker)); 821 if (value_sp) { 822 const bool can_create = true; 823 child_sp = value_sp->GetChildAtIndex(idx, can_create); 824 if (can_create_synthetic && !child_sp) { 825 child_sp = value_sp->GetSyntheticArrayMember(idx, can_create); 826 } 827 } 828 829 SBValue sb_value; 830 sb_value.SetSP(child_sp, use_dynamic, GetPreferSyntheticValue()); 831 if (log) 832 log->Printf("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", 833 static_cast<void *>(value_sp.get()), idx, 834 static_cast<void *>(value_sp.get())); 835 836 return sb_value; 837 } 838 839 uint32_t SBValue::GetIndexOfChildWithName(const char *name) { 840 uint32_t idx = UINT32_MAX; 841 ValueLocker locker; 842 lldb::ValueObjectSP value_sp(GetSP(locker)); 843 if (value_sp) { 844 idx = value_sp->GetIndexOfChildWithName(ConstString(name)); 845 } 846 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 847 if (log) { 848 if (idx == UINT32_MAX) 849 log->Printf( 850 "SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", 851 static_cast<void *>(value_sp.get()), name); 852 else 853 log->Printf("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", 854 static_cast<void *>(value_sp.get()), name, idx); 855 } 856 return idx; 857 } 858 859 SBValue SBValue::GetChildMemberWithName(const char *name) { 860 lldb::DynamicValueType use_dynamic_value = eNoDynamicValues; 861 TargetSP target_sp; 862 if (m_opaque_sp) 863 target_sp = m_opaque_sp->GetTargetSP(); 864 865 if (target_sp) 866 use_dynamic_value = target_sp->GetPreferDynamicValue(); 867 return GetChildMemberWithName(name, use_dynamic_value); 868 } 869 870 SBValue 871 SBValue::GetChildMemberWithName(const char *name, 872 lldb::DynamicValueType use_dynamic_value) { 873 lldb::ValueObjectSP child_sp; 874 const ConstString str_name(name); 875 876 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 877 878 ValueLocker locker; 879 lldb::ValueObjectSP value_sp(GetSP(locker)); 880 if (value_sp) { 881 child_sp = value_sp->GetChildMemberWithName(str_name, true); 882 } 883 884 SBValue sb_value; 885 sb_value.SetSP(child_sp, use_dynamic_value, GetPreferSyntheticValue()); 886 887 if (log) 888 log->Printf( 889 "SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", 890 static_cast<void *>(value_sp.get()), name, 891 static_cast<void *>(value_sp.get())); 892 893 return sb_value; 894 } 895 896 lldb::SBValue SBValue::GetDynamicValue(lldb::DynamicValueType use_dynamic) { 897 SBValue value_sb; 898 if (IsValid()) { 899 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(), use_dynamic, 900 m_opaque_sp->GetUseSynthetic())); 901 value_sb.SetSP(proxy_sp); 902 } 903 return value_sb; 904 } 905 906 lldb::SBValue SBValue::GetStaticValue() { 907 SBValue value_sb; 908 if (IsValid()) { 909 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(), 910 eNoDynamicValues, 911 m_opaque_sp->GetUseSynthetic())); 912 value_sb.SetSP(proxy_sp); 913 } 914 return value_sb; 915 } 916 917 lldb::SBValue SBValue::GetNonSyntheticValue() { 918 SBValue value_sb; 919 if (IsValid()) { 920 ValueImplSP proxy_sp(new ValueImpl(m_opaque_sp->GetRootSP(), 921 m_opaque_sp->GetUseDynamic(), false)); 922 value_sb.SetSP(proxy_sp); 923 } 924 return value_sb; 925 } 926 927 lldb::DynamicValueType SBValue::GetPreferDynamicValue() { 928 if (!IsValid()) 929 return eNoDynamicValues; 930 return m_opaque_sp->GetUseDynamic(); 931 } 932 933 void SBValue::SetPreferDynamicValue(lldb::DynamicValueType use_dynamic) { 934 if (IsValid()) 935 return m_opaque_sp->SetUseDynamic(use_dynamic); 936 } 937 938 bool SBValue::GetPreferSyntheticValue() { 939 if (!IsValid()) 940 return false; 941 return m_opaque_sp->GetUseSynthetic(); 942 } 943 944 void SBValue::SetPreferSyntheticValue(bool use_synthetic) { 945 if (IsValid()) 946 return m_opaque_sp->SetUseSynthetic(use_synthetic); 947 } 948 949 bool SBValue::IsDynamic() { 950 ValueLocker locker; 951 lldb::ValueObjectSP value_sp(GetSP(locker)); 952 if (value_sp) 953 return value_sp->IsDynamic(); 954 return false; 955 } 956 957 bool SBValue::IsSynthetic() { 958 ValueLocker locker; 959 lldb::ValueObjectSP value_sp(GetSP(locker)); 960 if (value_sp) 961 return value_sp->IsSynthetic(); 962 return false; 963 } 964 965 bool SBValue::IsSyntheticChildrenGenerated() { 966 ValueLocker locker; 967 lldb::ValueObjectSP value_sp(GetSP(locker)); 968 if (value_sp) 969 return value_sp->IsSyntheticChildrenGenerated(); 970 return false; 971 } 972 973 void SBValue::SetSyntheticChildrenGenerated(bool is) { 974 ValueLocker locker; 975 lldb::ValueObjectSP value_sp(GetSP(locker)); 976 if (value_sp) 977 return value_sp->SetSyntheticChildrenGenerated(is); 978 } 979 980 lldb::SBValue SBValue::GetValueForExpressionPath(const char *expr_path) { 981 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 982 lldb::ValueObjectSP child_sp; 983 ValueLocker locker; 984 lldb::ValueObjectSP value_sp(GetSP(locker)); 985 if (value_sp) { 986 // using default values for all the fancy options, just do it if you can 987 child_sp = value_sp->GetValueForExpressionPath(expr_path); 988 } 989 990 SBValue sb_value; 991 sb_value.SetSP(child_sp, GetPreferDynamicValue(), GetPreferSyntheticValue()); 992 993 if (log) 994 log->Printf("SBValue(%p)::GetValueForExpressionPath (expr_path=\"%s\") => " 995 "SBValue(%p)", 996 static_cast<void *>(value_sp.get()), expr_path, 997 static_cast<void *>(value_sp.get())); 998 999 return sb_value; 1000 } 1001 1002 int64_t SBValue::GetValueAsSigned(SBError &error, int64_t fail_value) { 1003 error.Clear(); 1004 ValueLocker locker; 1005 lldb::ValueObjectSP value_sp(GetSP(locker)); 1006 if (value_sp) { 1007 bool success = true; 1008 uint64_t ret_val = fail_value; 1009 ret_val = value_sp->GetValueAsSigned(fail_value, &success); 1010 if (!success) 1011 error.SetErrorString("could not resolve value"); 1012 return ret_val; 1013 } else 1014 error.SetErrorStringWithFormat("could not get SBValue: %s", 1015 locker.GetError().AsCString()); 1016 1017 return fail_value; 1018 } 1019 1020 uint64_t SBValue::GetValueAsUnsigned(SBError &error, uint64_t fail_value) { 1021 error.Clear(); 1022 ValueLocker locker; 1023 lldb::ValueObjectSP value_sp(GetSP(locker)); 1024 if (value_sp) { 1025 bool success = true; 1026 uint64_t ret_val = fail_value; 1027 ret_val = value_sp->GetValueAsUnsigned(fail_value, &success); 1028 if (!success) 1029 error.SetErrorString("could not resolve value"); 1030 return ret_val; 1031 } else 1032 error.SetErrorStringWithFormat("could not get SBValue: %s", 1033 locker.GetError().AsCString()); 1034 1035 return fail_value; 1036 } 1037 1038 int64_t SBValue::GetValueAsSigned(int64_t fail_value) { 1039 ValueLocker locker; 1040 lldb::ValueObjectSP value_sp(GetSP(locker)); 1041 if (value_sp) { 1042 return value_sp->GetValueAsSigned(fail_value); 1043 } 1044 return fail_value; 1045 } 1046 1047 uint64_t SBValue::GetValueAsUnsigned(uint64_t fail_value) { 1048 ValueLocker locker; 1049 lldb::ValueObjectSP value_sp(GetSP(locker)); 1050 if (value_sp) { 1051 return value_sp->GetValueAsUnsigned(fail_value); 1052 } 1053 return fail_value; 1054 } 1055 1056 bool SBValue::MightHaveChildren() { 1057 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 1058 bool has_children = false; 1059 ValueLocker locker; 1060 lldb::ValueObjectSP value_sp(GetSP(locker)); 1061 if (value_sp) 1062 has_children = value_sp->MightHaveChildren(); 1063 1064 if (log) 1065 log->Printf("SBValue(%p)::MightHaveChildren() => %i", 1066 static_cast<void *>(value_sp.get()), has_children); 1067 return has_children; 1068 } 1069 1070 bool SBValue::IsRuntimeSupportValue() { 1071 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 1072 bool is_support = false; 1073 ValueLocker locker; 1074 lldb::ValueObjectSP value_sp(GetSP(locker)); 1075 if (value_sp) 1076 is_support = value_sp->IsRuntimeSupportValue(); 1077 1078 if (log) 1079 log->Printf("SBValue(%p)::IsRuntimeSupportValue() => %i", 1080 static_cast<void *>(value_sp.get()), is_support); 1081 return is_support; 1082 } 1083 1084 uint32_t SBValue::GetNumChildren() { return GetNumChildren(UINT32_MAX); } 1085 1086 uint32_t SBValue::GetNumChildren(uint32_t max) { 1087 uint32_t num_children = 0; 1088 1089 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 1090 ValueLocker locker; 1091 lldb::ValueObjectSP value_sp(GetSP(locker)); 1092 if (value_sp) 1093 num_children = value_sp->GetNumChildren(max); 1094 1095 if (log) 1096 log->Printf("SBValue(%p)::GetNumChildren (%u) => %u", 1097 static_cast<void *>(value_sp.get()), max, num_children); 1098 1099 return num_children; 1100 } 1101 1102 SBValue SBValue::Dereference() { 1103 SBValue sb_value; 1104 ValueLocker locker; 1105 lldb::ValueObjectSP value_sp(GetSP(locker)); 1106 if (value_sp) { 1107 Status error; 1108 sb_value = value_sp->Dereference(error); 1109 } 1110 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 1111 if (log) 1112 log->Printf("SBValue(%p)::Dereference () => SBValue(%p)", 1113 static_cast<void *>(value_sp.get()), 1114 static_cast<void *>(value_sp.get())); 1115 1116 return sb_value; 1117 } 1118 1119 // Deprecated - please use GetType().IsPointerType() instead. 1120 bool SBValue::TypeIsPointerType() { return GetType().IsPointerType(); } 1121 1122 void *SBValue::GetOpaqueType() { 1123 ValueLocker locker; 1124 lldb::ValueObjectSP value_sp(GetSP(locker)); 1125 if (value_sp) 1126 return value_sp->GetCompilerType().GetOpaqueQualType(); 1127 return NULL; 1128 } 1129 1130 lldb::SBTarget SBValue::GetTarget() { 1131 SBTarget sb_target; 1132 TargetSP target_sp; 1133 if (m_opaque_sp) { 1134 target_sp = m_opaque_sp->GetTargetSP(); 1135 sb_target.SetSP(target_sp); 1136 } 1137 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 1138 if (log) { 1139 if (target_sp.get() == NULL) 1140 log->Printf("SBValue(%p)::GetTarget () => NULL", 1141 static_cast<void *>(m_opaque_sp.get())); 1142 else 1143 log->Printf("SBValue(%p)::GetTarget () => %p", 1144 static_cast<void *>(m_opaque_sp.get()), 1145 static_cast<void *>(target_sp.get())); 1146 } 1147 return sb_target; 1148 } 1149 1150 lldb::SBProcess SBValue::GetProcess() { 1151 SBProcess sb_process; 1152 ProcessSP process_sp; 1153 if (m_opaque_sp) { 1154 process_sp = m_opaque_sp->GetProcessSP(); 1155 sb_process.SetSP(process_sp); 1156 } 1157 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 1158 if (log) { 1159 if (process_sp.get() == NULL) 1160 log->Printf("SBValue(%p)::GetProcess () => NULL", 1161 static_cast<void *>(m_opaque_sp.get())); 1162 else 1163 log->Printf("SBValue(%p)::GetProcess () => %p", 1164 static_cast<void *>(m_opaque_sp.get()), 1165 static_cast<void *>(process_sp.get())); 1166 } 1167 return sb_process; 1168 } 1169 1170 lldb::SBThread SBValue::GetThread() { 1171 SBThread sb_thread; 1172 ThreadSP thread_sp; 1173 if (m_opaque_sp) { 1174 thread_sp = m_opaque_sp->GetThreadSP(); 1175 sb_thread.SetThread(thread_sp); 1176 } 1177 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 1178 if (log) { 1179 if (thread_sp.get() == NULL) 1180 log->Printf("SBValue(%p)::GetThread () => NULL", 1181 static_cast<void *>(m_opaque_sp.get())); 1182 else 1183 log->Printf("SBValue(%p)::GetThread () => %p", 1184 static_cast<void *>(m_opaque_sp.get()), 1185 static_cast<void *>(thread_sp.get())); 1186 } 1187 return sb_thread; 1188 } 1189 1190 lldb::SBFrame SBValue::GetFrame() { 1191 SBFrame sb_frame; 1192 StackFrameSP frame_sp; 1193 if (m_opaque_sp) { 1194 frame_sp = m_opaque_sp->GetFrameSP(); 1195 sb_frame.SetFrameSP(frame_sp); 1196 } 1197 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 1198 if (log) { 1199 if (frame_sp.get() == NULL) 1200 log->Printf("SBValue(%p)::GetFrame () => NULL", 1201 static_cast<void *>(m_opaque_sp.get())); 1202 else 1203 log->Printf("SBValue(%p)::GetFrame () => %p", 1204 static_cast<void *>(m_opaque_sp.get()), 1205 static_cast<void *>(frame_sp.get())); 1206 } 1207 return sb_frame; 1208 } 1209 1210 lldb::ValueObjectSP SBValue::GetSP(ValueLocker &locker) const { 1211 if (!m_opaque_sp || !m_opaque_sp->IsValid()) { 1212 locker.GetError().SetErrorString("No value"); 1213 return ValueObjectSP(); 1214 } 1215 return locker.GetLockedSP(*m_opaque_sp.get()); 1216 } 1217 1218 lldb::ValueObjectSP SBValue::GetSP() const { 1219 ValueLocker locker; 1220 return GetSP(locker); 1221 } 1222 1223 void SBValue::SetSP(ValueImplSP impl_sp) { m_opaque_sp = impl_sp; } 1224 1225 void SBValue::SetSP(const lldb::ValueObjectSP &sp) { 1226 if (sp) { 1227 lldb::TargetSP target_sp(sp->GetTargetSP()); 1228 if (target_sp) { 1229 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue(); 1230 bool use_synthetic = 1231 target_sp->TargetProperties::GetEnableSyntheticValue(); 1232 m_opaque_sp = ValueImplSP(new ValueImpl(sp, use_dynamic, use_synthetic)); 1233 } else 1234 m_opaque_sp = ValueImplSP(new ValueImpl(sp, eNoDynamicValues, true)); 1235 } else 1236 m_opaque_sp = ValueImplSP(new ValueImpl(sp, eNoDynamicValues, false)); 1237 } 1238 1239 void SBValue::SetSP(const lldb::ValueObjectSP &sp, 1240 lldb::DynamicValueType use_dynamic) { 1241 if (sp) { 1242 lldb::TargetSP target_sp(sp->GetTargetSP()); 1243 if (target_sp) { 1244 bool use_synthetic = 1245 target_sp->TargetProperties::GetEnableSyntheticValue(); 1246 SetSP(sp, use_dynamic, use_synthetic); 1247 } else 1248 SetSP(sp, use_dynamic, true); 1249 } else 1250 SetSP(sp, use_dynamic, false); 1251 } 1252 1253 void SBValue::SetSP(const lldb::ValueObjectSP &sp, bool use_synthetic) { 1254 if (sp) { 1255 lldb::TargetSP target_sp(sp->GetTargetSP()); 1256 if (target_sp) { 1257 lldb::DynamicValueType use_dynamic = target_sp->GetPreferDynamicValue(); 1258 SetSP(sp, use_dynamic, use_synthetic); 1259 } else 1260 SetSP(sp, eNoDynamicValues, use_synthetic); 1261 } else 1262 SetSP(sp, eNoDynamicValues, use_synthetic); 1263 } 1264 1265 void SBValue::SetSP(const lldb::ValueObjectSP &sp, 1266 lldb::DynamicValueType use_dynamic, bool use_synthetic) { 1267 m_opaque_sp = ValueImplSP(new ValueImpl(sp, use_dynamic, use_synthetic)); 1268 } 1269 1270 void SBValue::SetSP(const lldb::ValueObjectSP &sp, 1271 lldb::DynamicValueType use_dynamic, bool use_synthetic, 1272 const char *name) { 1273 m_opaque_sp = 1274 ValueImplSP(new ValueImpl(sp, use_dynamic, use_synthetic, name)); 1275 } 1276 1277 bool SBValue::GetExpressionPath(SBStream &description) { 1278 ValueLocker locker; 1279 lldb::ValueObjectSP value_sp(GetSP(locker)); 1280 if (value_sp) { 1281 value_sp->GetExpressionPath(description.ref(), false); 1282 return true; 1283 } 1284 return false; 1285 } 1286 1287 bool SBValue::GetExpressionPath(SBStream &description, 1288 bool qualify_cxx_base_classes) { 1289 ValueLocker locker; 1290 lldb::ValueObjectSP value_sp(GetSP(locker)); 1291 if (value_sp) { 1292 value_sp->GetExpressionPath(description.ref(), qualify_cxx_base_classes); 1293 return true; 1294 } 1295 return false; 1296 } 1297 1298 bool SBValue::GetDescription(SBStream &description) { 1299 Stream &strm = description.ref(); 1300 1301 ValueLocker locker; 1302 lldb::ValueObjectSP value_sp(GetSP(locker)); 1303 if (value_sp) 1304 value_sp->Dump(strm); 1305 else 1306 strm.PutCString("No value"); 1307 1308 return true; 1309 } 1310 1311 lldb::Format SBValue::GetFormat() { 1312 ValueLocker locker; 1313 lldb::ValueObjectSP value_sp(GetSP(locker)); 1314 if (value_sp) 1315 return value_sp->GetFormat(); 1316 return eFormatDefault; 1317 } 1318 1319 void SBValue::SetFormat(lldb::Format format) { 1320 ValueLocker locker; 1321 lldb::ValueObjectSP value_sp(GetSP(locker)); 1322 if (value_sp) 1323 value_sp->SetFormat(format); 1324 } 1325 1326 lldb::SBValue SBValue::AddressOf() { 1327 SBValue sb_value; 1328 ValueLocker locker; 1329 lldb::ValueObjectSP value_sp(GetSP(locker)); 1330 if (value_sp) { 1331 Status error; 1332 sb_value.SetSP(value_sp->AddressOf(error), GetPreferDynamicValue(), 1333 GetPreferSyntheticValue()); 1334 } 1335 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 1336 if (log) 1337 log->Printf("SBValue(%p)::AddressOf () => SBValue(%p)", 1338 static_cast<void *>(value_sp.get()), 1339 static_cast<void *>(value_sp.get())); 1340 1341 return sb_value; 1342 } 1343 1344 lldb::addr_t SBValue::GetLoadAddress() { 1345 lldb::addr_t value = LLDB_INVALID_ADDRESS; 1346 ValueLocker locker; 1347 lldb::ValueObjectSP value_sp(GetSP(locker)); 1348 if (value_sp) { 1349 TargetSP target_sp(value_sp->GetTargetSP()); 1350 if (target_sp) { 1351 const bool scalar_is_load_address = true; 1352 AddressType addr_type; 1353 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type); 1354 if (addr_type == eAddressTypeFile) { 1355 ModuleSP module_sp(value_sp->GetModule()); 1356 if (!module_sp) 1357 value = LLDB_INVALID_ADDRESS; 1358 else { 1359 Address addr; 1360 module_sp->ResolveFileAddress(value, addr); 1361 value = addr.GetLoadAddress(target_sp.get()); 1362 } 1363 } else if (addr_type == eAddressTypeHost || 1364 addr_type == eAddressTypeInvalid) 1365 value = LLDB_INVALID_ADDRESS; 1366 } 1367 } 1368 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 1369 if (log) 1370 log->Printf("SBValue(%p)::GetLoadAddress () => (%" PRIu64 ")", 1371 static_cast<void *>(value_sp.get()), value); 1372 1373 return value; 1374 } 1375 1376 lldb::SBAddress SBValue::GetAddress() { 1377 Address addr; 1378 ValueLocker locker; 1379 lldb::ValueObjectSP value_sp(GetSP(locker)); 1380 if (value_sp) { 1381 TargetSP target_sp(value_sp->GetTargetSP()); 1382 if (target_sp) { 1383 lldb::addr_t value = LLDB_INVALID_ADDRESS; 1384 const bool scalar_is_load_address = true; 1385 AddressType addr_type; 1386 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type); 1387 if (addr_type == eAddressTypeFile) { 1388 ModuleSP module_sp(value_sp->GetModule()); 1389 if (module_sp) 1390 module_sp->ResolveFileAddress(value, addr); 1391 } else if (addr_type == eAddressTypeLoad) { 1392 // no need to check the return value on this.. if it can actually do 1393 // the resolve addr will be in the form (section,offset), otherwise it 1394 // will simply be returned as (NULL, value) 1395 addr.SetLoadAddress(value, target_sp.get()); 1396 } 1397 } 1398 } 1399 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 1400 if (log) 1401 log->Printf("SBValue(%p)::GetAddress () => (%s,%" PRIu64 ")", 1402 static_cast<void *>(value_sp.get()), 1403 (addr.GetSection() ? addr.GetSection()->GetName().GetCString() 1404 : "NULL"), 1405 addr.GetOffset()); 1406 return SBAddress(new Address(addr)); 1407 } 1408 1409 lldb::SBData SBValue::GetPointeeData(uint32_t item_idx, uint32_t item_count) { 1410 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 1411 lldb::SBData sb_data; 1412 ValueLocker locker; 1413 lldb::ValueObjectSP value_sp(GetSP(locker)); 1414 if (value_sp) { 1415 TargetSP target_sp(value_sp->GetTargetSP()); 1416 if (target_sp) { 1417 DataExtractorSP data_sp(new DataExtractor()); 1418 value_sp->GetPointeeData(*data_sp, item_idx, item_count); 1419 if (data_sp->GetByteSize() > 0) 1420 *sb_data = data_sp; 1421 } 1422 } 1423 if (log) 1424 log->Printf("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)", 1425 static_cast<void *>(value_sp.get()), item_idx, item_count, 1426 static_cast<void *>(sb_data.get())); 1427 1428 return sb_data; 1429 } 1430 1431 lldb::SBData SBValue::GetData() { 1432 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 1433 lldb::SBData sb_data; 1434 ValueLocker locker; 1435 lldb::ValueObjectSP value_sp(GetSP(locker)); 1436 if (value_sp) { 1437 DataExtractorSP data_sp(new DataExtractor()); 1438 Status error; 1439 value_sp->GetData(*data_sp, error); 1440 if (error.Success()) 1441 *sb_data = data_sp; 1442 } 1443 if (log) 1444 log->Printf("SBValue(%p)::GetData () => SBData(%p)", 1445 static_cast<void *>(value_sp.get()), 1446 static_cast<void *>(sb_data.get())); 1447 1448 return sb_data; 1449 } 1450 1451 bool SBValue::SetData(lldb::SBData &data, SBError &error) { 1452 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 1453 ValueLocker locker; 1454 lldb::ValueObjectSP value_sp(GetSP(locker)); 1455 bool ret = true; 1456 1457 if (value_sp) { 1458 DataExtractor *data_extractor = data.get(); 1459 1460 if (!data_extractor) { 1461 if (log) 1462 log->Printf("SBValue(%p)::SetData() => error: no data to set", 1463 static_cast<void *>(value_sp.get())); 1464 1465 error.SetErrorString("No data to set"); 1466 ret = false; 1467 } else { 1468 Status set_error; 1469 1470 value_sp->SetData(*data_extractor, set_error); 1471 1472 if (!set_error.Success()) { 1473 error.SetErrorStringWithFormat("Couldn't set data: %s", 1474 set_error.AsCString()); 1475 ret = false; 1476 } 1477 } 1478 } else { 1479 error.SetErrorStringWithFormat( 1480 "Couldn't set data: could not get SBValue: %s", 1481 locker.GetError().AsCString()); 1482 ret = false; 1483 } 1484 1485 if (log) 1486 log->Printf("SBValue(%p)::SetData (%p) => %s", 1487 static_cast<void *>(value_sp.get()), 1488 static_cast<void *>(data.get()), ret ? "true" : "false"); 1489 return ret; 1490 } 1491 1492 lldb::SBDeclaration SBValue::GetDeclaration() { 1493 ValueLocker locker; 1494 lldb::ValueObjectSP value_sp(GetSP(locker)); 1495 SBDeclaration decl_sb; 1496 if (value_sp) { 1497 Declaration decl; 1498 if (value_sp->GetDeclaration(decl)) 1499 decl_sb.SetDeclaration(decl); 1500 } 1501 return decl_sb; 1502 } 1503 1504 lldb::SBWatchpoint SBValue::Watch(bool resolve_location, bool read, bool write, 1505 SBError &error) { 1506 SBWatchpoint sb_watchpoint; 1507 1508 // If the SBValue is not valid, there's no point in even trying to watch it. 1509 ValueLocker locker; 1510 lldb::ValueObjectSP value_sp(GetSP(locker)); 1511 TargetSP target_sp(GetTarget().GetSP()); 1512 if (value_sp && target_sp) { 1513 // Read and Write cannot both be false. 1514 if (!read && !write) 1515 return sb_watchpoint; 1516 1517 // If the value is not in scope, don't try and watch and invalid value 1518 if (!IsInScope()) 1519 return sb_watchpoint; 1520 1521 addr_t addr = GetLoadAddress(); 1522 if (addr == LLDB_INVALID_ADDRESS) 1523 return sb_watchpoint; 1524 size_t byte_size = GetByteSize(); 1525 if (byte_size == 0) 1526 return sb_watchpoint; 1527 1528 uint32_t watch_type = 0; 1529 if (read) 1530 watch_type |= LLDB_WATCH_TYPE_READ; 1531 if (write) 1532 watch_type |= LLDB_WATCH_TYPE_WRITE; 1533 1534 Status rc; 1535 CompilerType type(value_sp->GetCompilerType()); 1536 WatchpointSP watchpoint_sp = 1537 target_sp->CreateWatchpoint(addr, byte_size, &type, watch_type, rc); 1538 error.SetError(rc); 1539 1540 if (watchpoint_sp) { 1541 sb_watchpoint.SetSP(watchpoint_sp); 1542 Declaration decl; 1543 if (value_sp->GetDeclaration(decl)) { 1544 if (decl.GetFile()) { 1545 StreamString ss; 1546 // True to show fullpath for declaration file. 1547 decl.DumpStopContext(&ss, true); 1548 watchpoint_sp->SetDeclInfo(ss.GetString()); 1549 } 1550 } 1551 } 1552 } else if (target_sp) { 1553 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 1554 if (log) 1555 log->Printf("SBValue(%p)::Watch() => error getting SBValue: %s", 1556 static_cast<void *>(value_sp.get()), 1557 locker.GetError().AsCString()); 1558 1559 error.SetErrorStringWithFormat("could not get SBValue: %s", 1560 locker.GetError().AsCString()); 1561 } else { 1562 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 1563 if (log) 1564 log->Printf("SBValue(%p)::Watch() => error getting SBValue: no target", 1565 static_cast<void *>(value_sp.get())); 1566 error.SetErrorString("could not set watchpoint, a target is required"); 1567 } 1568 1569 return sb_watchpoint; 1570 } 1571 1572 // FIXME: Remove this method impl (as well as the decl in .h) once it is no 1573 // longer needed. 1574 // Backward compatibility fix in the interim. 1575 lldb::SBWatchpoint SBValue::Watch(bool resolve_location, bool read, 1576 bool write) { 1577 SBError error; 1578 return Watch(resolve_location, read, write, error); 1579 } 1580 1581 lldb::SBWatchpoint SBValue::WatchPointee(bool resolve_location, bool read, 1582 bool write, SBError &error) { 1583 SBWatchpoint sb_watchpoint; 1584 if (IsInScope() && GetType().IsPointerType()) 1585 sb_watchpoint = Dereference().Watch(resolve_location, read, write, error); 1586 return sb_watchpoint; 1587 } 1588 1589 lldb::SBValue SBValue::Persist() { 1590 ValueLocker locker; 1591 lldb::ValueObjectSP value_sp(GetSP(locker)); 1592 SBValue persisted_sb; 1593 if (value_sp) { 1594 persisted_sb.SetSP(value_sp->Persist()); 1595 } 1596 return persisted_sb; 1597 } 1598