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