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