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