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