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