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