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