SBValue.cpp revision dc0a38c5a727cae5362b218a3180d0f4265a619d
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/SBStream.h" 13#include "lldb/API/SBTypeFilter.h" 14#include "lldb/API/SBTypeFormat.h" 15#include "lldb/API/SBTypeSummary.h" 16#include "lldb/API/SBTypeSynthetic.h" 17 18#include "lldb/Breakpoint/Watchpoint.h" 19#include "lldb/Core/DataExtractor.h" 20#include "lldb/Core/DataVisualization.h" 21#include "lldb/Core/Log.h" 22#include "lldb/Core/Module.h" 23#include "lldb/Core/Scalar.h" 24#include "lldb/Core/Stream.h" 25#include "lldb/Core/StreamFile.h" 26#include "lldb/Core/Value.h" 27#include "lldb/Core/ValueObject.h" 28#include "lldb/Core/ValueObjectConstResult.h" 29#include "lldb/Symbol/Block.h" 30#include "lldb/Symbol/ObjectFile.h" 31#include "lldb/Symbol/Type.h" 32#include "lldb/Symbol/Variable.h" 33#include "lldb/Symbol/VariableList.h" 34#include "lldb/Target/ExecutionContext.h" 35#include "lldb/Target/Process.h" 36#include "lldb/Target/StackFrame.h" 37#include "lldb/Target/Target.h" 38#include "lldb/Target/Thread.h" 39 40#include "lldb/API/SBProcess.h" 41#include "lldb/API/SBTarget.h" 42#include "lldb/API/SBThread.h" 43#include "lldb/API/SBFrame.h" 44#include "lldb/API/SBDebugger.h" 45 46using namespace lldb; 47using namespace lldb_private; 48 49SBValue::SBValue () : 50 m_opaque_sp () 51{ 52} 53 54SBValue::SBValue (const lldb::ValueObjectSP &value_sp) : 55 m_opaque_sp (value_sp) 56{ 57} 58 59SBValue::SBValue(const SBValue &rhs) : 60 m_opaque_sp (rhs.m_opaque_sp) 61{ 62} 63 64SBValue & 65SBValue::operator = (const SBValue &rhs) 66{ 67 if (this != &rhs) 68 m_opaque_sp = rhs.m_opaque_sp; 69 return *this; 70} 71 72SBValue::~SBValue() 73{ 74} 75 76bool 77SBValue::IsValid () 78{ 79 // If this function ever changes to anything that does more than just 80 // check if the opaque shared pointer is non NULL, then we need to update 81 // all "if (m_opaque_sp)" code in this file. 82 return m_opaque_sp.get() != NULL; 83} 84 85void 86SBValue::Clear() 87{ 88 m_opaque_sp.reset(); 89} 90 91SBError 92SBValue::GetError() 93{ 94 SBError sb_error; 95 96 lldb::ValueObjectSP value_sp(GetSP()); 97 if (value_sp) 98 sb_error.SetError(value_sp->GetError()); 99 else 100 sb_error.SetErrorString("error: invalid value"); 101 102 return sb_error; 103} 104 105user_id_t 106SBValue::GetID() 107{ 108 lldb::ValueObjectSP value_sp(GetSP()); 109 if (value_sp) 110 return value_sp->GetID(); 111 return LLDB_INVALID_UID; 112} 113 114const char * 115SBValue::GetName() 116{ 117 118 const char *name = NULL; 119 lldb::ValueObjectSP value_sp(GetSP()); 120 if (value_sp) 121 name = value_sp->GetName().GetCString(); 122 123 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 124 if (log) 125 { 126 if (name) 127 log->Printf ("SBValue(%p)::GetName () => \"%s\"", value_sp.get(), name); 128 else 129 log->Printf ("SBValue(%p)::GetName () => NULL", value_sp.get()); 130 } 131 132 return name; 133} 134 135const char * 136SBValue::GetTypeName () 137{ 138 const char *name = NULL; 139 lldb::ValueObjectSP value_sp(GetSP()); 140 if (value_sp) 141 //name = value_sp->GetTypeName().GetCString(); 142 name = value_sp->GetQualifiedTypeName().GetCString(); 143 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 144 if (log) 145 { 146 if (name) 147 log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"", value_sp.get(), name); 148 else 149 log->Printf ("SBValue(%p)::GetTypeName () => NULL", value_sp.get()); 150 } 151 152 return name; 153} 154 155size_t 156SBValue::GetByteSize () 157{ 158 size_t result = 0; 159 160 lldb::ValueObjectSP value_sp(GetSP()); 161 if (value_sp) 162 result = value_sp->GetByteSize(); 163 164 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 165 if (log) 166 log->Printf ("SBValue(%p)::GetByteSize () => %zu", value_sp.get(), result); 167 168 return result; 169} 170 171bool 172SBValue::IsInScope () 173{ 174 bool result = false; 175 176 lldb::ValueObjectSP value_sp(GetSP()); 177 if (value_sp) 178 { 179 TargetSP target_sp(value_sp->GetTargetSP()); 180 if (target_sp) 181 { 182 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 183 result = value_sp->IsInScope (); 184 } 185 } 186 187 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 188 if (log) 189 log->Printf ("SBValue(%p)::IsInScope () => %i", value_sp.get(), result); 190 191 return result; 192} 193 194const char * 195SBValue::GetValue () 196{ 197 const char *cstr = NULL; 198 lldb::ValueObjectSP value_sp(GetSP()); 199 if (value_sp) 200 { 201 TargetSP target_sp(value_sp->GetTargetSP()); 202 if (target_sp) 203 { 204 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 205 cstr = value_sp->GetValueAsCString (); 206 } 207 } 208 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 209 if (log) 210 { 211 if (cstr) 212 log->Printf ("SBValue(%p)::GetValue => \"%s\"", value_sp.get(), cstr); 213 else 214 log->Printf ("SBValue(%p)::GetValue => NULL", value_sp.get()); 215 } 216 217 return cstr; 218} 219 220ValueType 221SBValue::GetValueType () 222{ 223 ValueType result = eValueTypeInvalid; 224 lldb::ValueObjectSP value_sp(GetSP()); 225 if (value_sp) 226 result = value_sp->GetValueType(); 227 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 228 if (log) 229 { 230 switch (result) 231 { 232 case eValueTypeInvalid: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeInvalid", value_sp.get()); break; 233 case eValueTypeVariableGlobal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableGlobal", value_sp.get()); break; 234 case eValueTypeVariableStatic: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableStatic", value_sp.get()); break; 235 case eValueTypeVariableArgument:log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableArgument", value_sp.get()); break; 236 case eValueTypeVariableLocal: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeVariableLocal", value_sp.get()); break; 237 case eValueTypeRegister: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegister", value_sp.get()); break; 238 case eValueTypeRegisterSet: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeRegisterSet", value_sp.get()); break; 239 case eValueTypeConstResult: log->Printf ("SBValue(%p)::GetValueType () => eValueTypeConstResult", value_sp.get()); break; 240 default: log->Printf ("SBValue(%p)::GetValueType () => %i ???", value_sp.get(), result); break; 241 } 242 } 243 return result; 244} 245 246const char * 247SBValue::GetObjectDescription () 248{ 249 const char *cstr = NULL; 250 lldb::ValueObjectSP value_sp(GetSP()); 251 if (value_sp) 252 { 253 TargetSP target_sp(value_sp->GetTargetSP()); 254 if (target_sp) 255 { 256 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 257 cstr = value_sp->GetObjectDescription (); 258 } 259 } 260 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 261 if (log) 262 { 263 if (cstr) 264 log->Printf ("SBValue(%p)::GetObjectDescription => \"%s\"", value_sp.get(), cstr); 265 else 266 log->Printf ("SBValue(%p)::GetObjectDescription => NULL", value_sp.get()); 267 } 268 return cstr; 269} 270 271SBType 272SBValue::GetType() 273{ 274 SBType sb_type; 275 lldb::ValueObjectSP value_sp(GetSP()); 276 TypeImplSP type_sp; 277 if (value_sp) 278 { 279 type_sp.reset (new TypeImpl(ClangASTType (value_sp->GetClangAST(), value_sp->GetClangType()))); 280 sb_type.SetSP(type_sp); 281 } 282 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 283 if (log) 284 { 285 if (type_sp) 286 log->Printf ("SBValue(%p)::GetType => SBType(%p)", value_sp.get(), type_sp.get()); 287 else 288 log->Printf ("SBValue(%p)::GetType => NULL", value_sp.get()); 289 } 290 return sb_type; 291} 292 293bool 294SBValue::GetValueDidChange () 295{ 296 bool result = false; 297 lldb::ValueObjectSP value_sp(GetSP()); 298 if (value_sp) 299 { 300 TargetSP target_sp(value_sp->GetTargetSP()); 301 if (target_sp) 302 { 303 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 304 result = value_sp->GetValueDidChange (); 305 } 306 } 307 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 308 if (log) 309 log->Printf ("SBValue(%p)::GetValueDidChange => %i", value_sp.get(), result); 310 311 return result; 312} 313 314#ifndef LLDB_DISABLE_PYTHON 315const char * 316SBValue::GetSummary () 317{ 318 const char *cstr = NULL; 319 lldb::ValueObjectSP value_sp(GetSP()); 320 if (value_sp) 321 { 322 TargetSP target_sp(value_sp->GetTargetSP()); 323 if (target_sp) 324 { 325 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 326 cstr = value_sp->GetSummaryAsCString(); 327 } 328 } 329 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 330 if (log) 331 { 332 if (cstr) 333 log->Printf ("SBValue(%p)::GetSummary => \"%s\"", value_sp.get(), cstr); 334 else 335 log->Printf ("SBValue(%p)::GetSummary => NULL", value_sp.get()); 336 } 337 return cstr; 338} 339#endif // LLDB_DISABLE_PYTHON 340 341const char * 342SBValue::GetLocation () 343{ 344 const char *cstr = NULL; 345 lldb::ValueObjectSP value_sp(GetSP()); 346 if (value_sp) 347 { 348 TargetSP target_sp(value_sp->GetTargetSP()); 349 if (target_sp) 350 { 351 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 352 cstr = value_sp->GetLocationAsCString(); 353 } 354 } 355 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 356 if (log) 357 { 358 if (cstr) 359 log->Printf ("SBValue(%p)::GetSummary => \"%s\"", value_sp.get(), cstr); 360 else 361 log->Printf ("SBValue(%p)::GetSummary => NULL", value_sp.get()); 362 } 363 return cstr; 364} 365 366bool 367SBValue::SetValueFromCString (const char *value_str) 368{ 369 bool success = false; 370 lldb::ValueObjectSP value_sp(GetSP()); 371 if (value_sp) 372 { 373 TargetSP target_sp(value_sp->GetTargetSP()); 374 if (target_sp) 375 { 376 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 377 success = value_sp->SetValueFromCString (value_str); 378 } 379 } 380 return success; 381} 382 383lldb::SBTypeFormat 384SBValue::GetTypeFormat () 385{ 386 lldb::SBTypeFormat format; 387 lldb::ValueObjectSP value_sp(GetSP()); 388 if (value_sp) 389 { 390 TargetSP target_sp(value_sp->GetTargetSP()); 391 if (target_sp) 392 { 393 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 394 if (value_sp->UpdateValueIfNeeded(true)) 395 { 396 lldb::TypeFormatImplSP format_sp = value_sp->GetValueFormat(); 397 if (format_sp) 398 format.SetSP(format_sp); 399 } 400 } 401 } 402 return format; 403} 404 405#ifndef LLDB_DISABLE_PYTHON 406lldb::SBTypeSummary 407SBValue::GetTypeSummary () 408{ 409 lldb::SBTypeSummary summary; 410 lldb::ValueObjectSP value_sp(GetSP()); 411 if (value_sp) 412 { 413 TargetSP target_sp(value_sp->GetTargetSP()); 414 if (target_sp) 415 { 416 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 417 if (value_sp->UpdateValueIfNeeded(true)) 418 { 419 lldb::TypeSummaryImplSP summary_sp = value_sp->GetSummaryFormat(); 420 if (summary_sp) 421 summary.SetSP(summary_sp); 422 } 423 } 424 } 425 return summary; 426} 427#endif // LLDB_DISABLE_PYTHON 428 429lldb::SBTypeFilter 430SBValue::GetTypeFilter () 431{ 432 lldb::SBTypeFilter filter; 433 lldb::ValueObjectSP value_sp(GetSP()); 434 if (value_sp) 435 { 436 TargetSP target_sp(value_sp->GetTargetSP()); 437 if (target_sp) 438 { 439 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 440 if (value_sp->UpdateValueIfNeeded(true)) 441 { 442 lldb::SyntheticChildrenSP synthetic_sp = value_sp->GetSyntheticChildren(); 443 444 if (synthetic_sp && !synthetic_sp->IsScripted()) 445 { 446 TypeFilterImplSP filter_sp = STD_STATIC_POINTER_CAST(TypeFilterImpl,synthetic_sp); 447 filter.SetSP(filter_sp); 448 } 449 } 450 } 451 } 452 return filter; 453} 454 455#ifndef LLDB_DISABLE_PYTHON 456lldb::SBTypeSynthetic 457SBValue::GetTypeSynthetic () 458{ 459 lldb::SBTypeSynthetic synthetic; 460 lldb::ValueObjectSP value_sp(GetSP()); 461 if (value_sp) 462 { 463 TargetSP target_sp(value_sp->GetTargetSP()); 464 if (target_sp) 465 { 466 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 467 if (value_sp->UpdateValueIfNeeded(true)) 468 { 469 lldb::SyntheticChildrenSP children_sp = value_sp->GetSyntheticChildren(); 470 471 if (children_sp && children_sp->IsScripted()) 472 { 473 TypeSyntheticImplSP synth_sp = STD_STATIC_POINTER_CAST(TypeSyntheticImpl,children_sp); 474 synthetic.SetSP(synth_sp); 475 } 476 } 477 } 478 } 479 return synthetic; 480} 481#endif 482 483lldb::SBValue 484SBValue::CreateChildAtOffset (const char *name, uint32_t offset, SBType type) 485{ 486 lldb::SBValue sb_value; 487 lldb::ValueObjectSP value_sp(GetSP()); 488 lldb::ValueObjectSP new_value_sp; 489 if (value_sp) 490 { 491 TypeImplSP type_sp (type.GetSP()); 492 if (type.IsValid()) 493 { 494 sb_value = SBValue(value_sp->GetSyntheticChildAtOffset(offset, type_sp->GetClangASTType(), true)); 495 new_value_sp = sb_value.GetSP(); 496 if (new_value_sp) 497 new_value_sp->SetName(ConstString(name)); 498 } 499 } 500 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 501 if (log) 502 { 503 if (new_value_sp) 504 log->Printf ("SBValue(%p)::GetChildAtOffset => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString()); 505 else 506 log->Printf ("SBValue(%p)::GetChildAtOffset => NULL", value_sp.get()); 507 } 508 return sb_value; 509} 510 511lldb::SBValue 512SBValue::Cast (SBType type) 513{ 514 lldb::SBValue sb_value; 515 lldb::ValueObjectSP value_sp(GetSP()); 516 TypeImplSP type_sp (type.GetSP()); 517 if (value_sp && type_sp) 518 sb_value.SetSP(value_sp->Cast(type_sp->GetClangASTType())); 519 return sb_value; 520} 521 522lldb::SBValue 523SBValue::CreateValueFromExpression (const char *name, const char* expression) 524{ 525 lldb::SBValue sb_value; 526 lldb::ValueObjectSP value_sp(GetSP()); 527 lldb::ValueObjectSP new_value_sp; 528 if (value_sp) 529 { 530 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef()); 531 Target* target = exe_ctx.GetTargetPtr(); 532 if (target) 533 { 534 target->EvaluateExpression (expression, 535 exe_ctx.GetFramePtr(), 536 eExecutionPolicyOnlyWhenNeeded, 537 false, // coerce to id 538 true, // unwind on error 539 true, // keep in memory 540 eNoDynamicValues, 541 new_value_sp); 542 if (new_value_sp) 543 { 544 new_value_sp->SetName(ConstString(name)); 545 sb_value.SetSP(new_value_sp); 546 } 547 } 548 } 549 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 550 if (log) 551 { 552 if (new_value_sp) 553 log->Printf ("SBValue(%p)::GetChildFromExpression => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString()); 554 else 555 log->Printf ("SBValue(%p)::GetChildFromExpression => NULL", value_sp.get()); 556 } 557 return sb_value; 558} 559 560lldb::SBValue 561SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType sb_type) 562{ 563 lldb::SBValue sb_value; 564 lldb::ValueObjectSP value_sp(GetSP()); 565 lldb::ValueObjectSP new_value_sp; 566 lldb::TypeImplSP type_impl_sp (sb_type.GetSP()); 567 if (value_sp && type_impl_sp) 568 { 569 ClangASTType pointee_ast_type(type_impl_sp->GetASTContext(), type_impl_sp->GetClangASTType().GetPointerType ()); 570 lldb::TypeImplSP pointee_type_impl_sp (new TypeImpl(pointee_ast_type)); 571 if (pointee_type_impl_sp) 572 { 573 574 lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t))); 575 576 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef()); 577 ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), 578 pointee_type_impl_sp->GetASTContext(), 579 pointee_type_impl_sp->GetOpaqueQualType(), 580 ConstString(name), 581 buffer, 582 lldb::endian::InlHostByteOrder(), 583 exe_ctx.GetAddressByteSize())); 584 585 if (ptr_result_valobj_sp) 586 { 587 ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress); 588 Error err; 589 new_value_sp = ptr_result_valobj_sp->Dereference(err); 590 if (new_value_sp) 591 new_value_sp->SetName(ConstString(name)); 592 } 593 sb_value.SetSP(new_value_sp); 594 } 595 } 596 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 597 if (log) 598 { 599 if (new_value_sp) 600 log->Printf ("SBValue(%p)::CreateValueFromAddress => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString()); 601 else 602 log->Printf ("SBValue(%p)::CreateValueFromAddress => NULL", value_sp.get()); 603 } 604 return sb_value; 605} 606 607lldb::SBValue 608SBValue::CreateValueFromData (const char* name, SBData data, SBType type) 609{ 610 lldb::SBValue sb_value; 611 lldb::ValueObjectSP new_value_sp; 612 lldb::ValueObjectSP value_sp(GetSP()); 613 if (value_sp) 614 { 615 ExecutionContext exe_ctx (value_sp->GetExecutionContextRef()); 616 617 new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), 618 type.m_opaque_sp->GetASTContext() , 619 type.m_opaque_sp->GetOpaqueQualType(), 620 ConstString(name), 621 *data.m_opaque_sp, 622 LLDB_INVALID_ADDRESS); 623 new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad); 624 sb_value.SetSP(new_value_sp); 625 } 626 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 627 if (log) 628 { 629 if (new_value_sp) 630 log->Printf ("SBValue(%p)::GetChildFromExpression => \"%s\"", value_sp.get(), new_value_sp->GetName().AsCString()); 631 else 632 log->Printf ("SBValue(%p)::GetChildFromExpression => NULL", value_sp.get()); 633 } 634 return sb_value; 635} 636 637SBValue 638SBValue::GetChildAtIndex (uint32_t idx) 639{ 640 const bool can_create_synthetic = false; 641 lldb::DynamicValueType use_dynamic = eNoDynamicValues; 642 lldb::ValueObjectSP value_sp(GetSP()); 643 if (value_sp) 644 { 645 TargetSP target_sp(value_sp->GetTargetSP()); 646 if (target_sp) 647 use_dynamic = target_sp->GetPreferDynamicValue(); 648 } 649 return GetChildAtIndex (idx, use_dynamic, can_create_synthetic); 650} 651 652SBValue 653SBValue::GetChildAtIndex (uint32_t idx, lldb::DynamicValueType use_dynamic, bool can_create_synthetic) 654{ 655 lldb::ValueObjectSP child_sp; 656 657 lldb::ValueObjectSP value_sp(GetSP()); 658 if (value_sp) 659 { 660 TargetSP target_sp(value_sp->GetTargetSP()); 661 if (target_sp) 662 { 663 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 664 const bool can_create = true; 665 child_sp = value_sp->GetChildAtIndex (idx, can_create); 666 if (can_create_synthetic && !child_sp) 667 { 668 if (value_sp->IsPointerType()) 669 { 670 child_sp = value_sp->GetSyntheticArrayMemberFromPointer(idx, can_create); 671 } 672 else if (value_sp->IsArrayType()) 673 { 674 child_sp = value_sp->GetSyntheticArrayMemberFromArray(idx, can_create); 675 } 676 } 677 678 if (child_sp) 679 { 680 if (use_dynamic != lldb::eNoDynamicValues) 681 { 682 lldb::ValueObjectSP dynamic_sp(child_sp->GetDynamicValue (use_dynamic)); 683 if (dynamic_sp) 684 child_sp = dynamic_sp; 685 } 686 } 687 } 688 } 689 690 SBValue sb_value (child_sp); 691 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 692 if (log) 693 log->Printf ("SBValue(%p)::GetChildAtIndex (%u) => SBValue(%p)", value_sp.get(), idx, value_sp.get()); 694 695 return sb_value; 696} 697 698uint32_t 699SBValue::GetIndexOfChildWithName (const char *name) 700{ 701 uint32_t idx = UINT32_MAX; 702 lldb::ValueObjectSP value_sp(GetSP()); 703 if (value_sp) 704 { 705 TargetSP target_sp(value_sp->GetTargetSP()); 706 if (target_sp) 707 { 708 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 709 710 idx = value_sp->GetIndexOfChildWithName (ConstString(name)); 711 } 712 } 713 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 714 if (log) 715 { 716 if (idx == UINT32_MAX) 717 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => NOT FOUND", value_sp.get(), name); 718 else 719 log->Printf ("SBValue(%p)::GetIndexOfChildWithName (name=\"%s\") => %u", value_sp.get(), name, idx); 720 } 721 return idx; 722} 723 724SBValue 725SBValue::GetChildMemberWithName (const char *name) 726{ 727 lldb::ValueObjectSP value_sp(GetSP()); 728 if (value_sp) 729 { 730 lldb::DynamicValueType use_dynamic_value = eNoDynamicValues; 731 TargetSP target_sp(value_sp->GetTargetSP()); 732 if (target_sp) 733 { 734 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 735 use_dynamic_value = target_sp->GetPreferDynamicValue(); 736 } 737 return GetChildMemberWithName (name, use_dynamic_value); 738 } 739 return SBValue(); 740} 741 742SBValue 743SBValue::GetChildMemberWithName (const char *name, lldb::DynamicValueType use_dynamic_value) 744{ 745 lldb::ValueObjectSP child_sp; 746 const ConstString str_name (name); 747 748 749 lldb::ValueObjectSP value_sp(GetSP()); 750 if (value_sp) 751 { 752 TargetSP target_sp(value_sp->GetTargetSP()); 753 if (target_sp) 754 { 755 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 756 child_sp = value_sp->GetChildMemberWithName (str_name, true); 757 if (use_dynamic_value != lldb::eNoDynamicValues) 758 { 759 if (child_sp) 760 { 761 lldb::ValueObjectSP dynamic_sp = child_sp->GetDynamicValue (use_dynamic_value); 762 if (dynamic_sp) 763 child_sp = dynamic_sp; 764 } 765 } 766 } 767 } 768 769 SBValue sb_value (child_sp); 770 771 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 772 if (log) 773 log->Printf ("SBValue(%p)::GetChildMemberWithName (name=\"%s\") => SBValue(%p)", value_sp.get(), name, value_sp.get()); 774 775 return sb_value; 776} 777 778lldb::SBValue 779SBValue::GetDynamicValue (lldb::DynamicValueType use_dynamic) 780{ 781 lldb::ValueObjectSP value_sp(GetSP()); 782 if (value_sp) 783 { 784 TargetSP target_sp(value_sp->GetTargetSP()); 785 if (target_sp) 786 { 787 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 788 return SBValue (value_sp->GetDynamicValue(use_dynamic)); 789 } 790 } 791 792 return SBValue(); 793} 794 795lldb::SBValue 796SBValue::GetStaticValue () 797{ 798 lldb::ValueObjectSP value_sp(GetSP()); 799 if (value_sp) 800 { 801 TargetSP target_sp(value_sp->GetTargetSP()); 802 if (target_sp) 803 { 804 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 805 return SBValue(value_sp->GetStaticValue()); 806 } 807 } 808 809 return SBValue(); 810} 811 812bool 813SBValue::IsDynamic() 814{ 815 lldb::ValueObjectSP value_sp(GetSP()); 816 if (value_sp) 817 { 818 TargetSP target_sp(value_sp->GetTargetSP()); 819 if (target_sp) 820 { 821 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 822 return value_sp->IsDynamic(); 823 } 824 } 825 return false; 826} 827 828lldb::SBValue 829SBValue::GetValueForExpressionPath(const char* expr_path) 830{ 831 lldb::ValueObjectSP child_sp; 832 lldb::ValueObjectSP value_sp(GetSP()); 833 if (value_sp) 834 { 835 TargetSP target_sp(value_sp->GetTargetSP()); 836 if (target_sp) 837 { 838 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 839 // using default values for all the fancy options, just do it if you can 840 child_sp = value_sp->GetValueForExpressionPath(expr_path); 841 } 842 } 843 844 SBValue sb_value (child_sp); 845 846 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 847 if (log) 848 log->Printf ("SBValue(%p)::GetValueForExpressionPath (expr_path=\"%s\") => SBValue(%p)", value_sp.get(), expr_path, value_sp.get()); 849 850 return sb_value; 851} 852 853int64_t 854SBValue::GetValueAsSigned(SBError& error, int64_t fail_value) 855{ 856 error.Clear(); 857 lldb::ValueObjectSP value_sp(GetSP()); 858 if (value_sp) 859 { 860 TargetSP target_sp(value_sp->GetTargetSP()); 861 if (target_sp) 862 { 863 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 864 Scalar scalar; 865 if (value_sp->ResolveValue (scalar)) 866 return scalar.GetRawBits64(fail_value); 867 else 868 error.SetErrorString("could not get value"); 869 } 870 else 871 error.SetErrorString("could not get target"); 872 } 873 error.SetErrorString("invalid SBValue"); 874 return fail_value; 875} 876 877uint64_t 878SBValue::GetValueAsUnsigned(SBError& error, uint64_t fail_value) 879{ 880 error.Clear(); 881 lldb::ValueObjectSP value_sp(GetSP()); 882 if (value_sp) 883 { 884 TargetSP target_sp(value_sp->GetTargetSP()); 885 if (target_sp) 886 { 887 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 888 Scalar scalar; 889 if (value_sp->ResolveValue (scalar)) 890 return scalar.GetRawBits64(fail_value); 891 else 892 error.SetErrorString("could not get value"); 893 } 894 else 895 error.SetErrorString("could not get target"); 896 } 897 error.SetErrorString("invalid SBValue"); 898 return fail_value; 899} 900 901int64_t 902SBValue::GetValueAsSigned(int64_t fail_value) 903{ 904 lldb::ValueObjectSP value_sp(GetSP()); 905 if (value_sp) 906 { 907 TargetSP target_sp(value_sp->GetTargetSP()); 908 if (target_sp) 909 { 910 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 911 Scalar scalar; 912 if (value_sp->ResolveValue (scalar)) 913 return scalar.GetRawBits64(fail_value); 914 } 915 } 916 return fail_value; 917} 918 919uint64_t 920SBValue::GetValueAsUnsigned(uint64_t fail_value) 921{ 922 lldb::ValueObjectSP value_sp(GetSP()); 923 if (value_sp) 924 { 925 TargetSP target_sp(value_sp->GetTargetSP()); 926 if (target_sp) 927 { 928 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 929 Scalar scalar; 930 if (value_sp->ResolveValue (scalar)) 931 return scalar.GetRawBits64(fail_value); 932 } 933 } 934 return fail_value; 935} 936 937uint32_t 938SBValue::GetNumChildren () 939{ 940 uint32_t num_children = 0; 941 942 lldb::ValueObjectSP value_sp(GetSP()); 943 if (value_sp) 944 { 945 TargetSP target_sp(value_sp->GetTargetSP()); 946 if (target_sp) 947 { 948 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 949 950 num_children = value_sp->GetNumChildren(); 951 } 952 } 953 954 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 955 if (log) 956 log->Printf ("SBValue(%p)::GetNumChildren () => %u", value_sp.get(), num_children); 957 958 return num_children; 959} 960 961 962SBValue 963SBValue::Dereference () 964{ 965 SBValue sb_value; 966 lldb::ValueObjectSP value_sp(GetSP()); 967 if (value_sp) 968 { 969 TargetSP target_sp(value_sp->GetTargetSP()); 970 if (target_sp) 971 { 972 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 973 974 Error error; 975 sb_value = value_sp->Dereference (error); 976 } 977 } 978 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 979 if (log) 980 log->Printf ("SBValue(%p)::Dereference () => SBValue(%p)", value_sp.get(), value_sp.get()); 981 982 return sb_value; 983} 984 985bool 986SBValue::TypeIsPointerType () 987{ 988 bool is_ptr_type = false; 989 990 lldb::ValueObjectSP value_sp(GetSP()); 991 if (value_sp) 992 { 993 TargetSP target_sp(value_sp->GetTargetSP()); 994 if (target_sp) 995 { 996 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 997 998 is_ptr_type = value_sp->IsPointerType(); 999 } 1000 } 1001 1002 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1003 if (log) 1004 log->Printf ("SBValue(%p)::TypeIsPointerType () => %i", value_sp.get(), is_ptr_type); 1005 1006 1007 return is_ptr_type; 1008} 1009 1010void * 1011SBValue::GetOpaqueType() 1012{ 1013 lldb::ValueObjectSP value_sp(GetSP()); 1014 if (value_sp) 1015 { 1016 TargetSP target_sp(value_sp->GetTargetSP()); 1017 if (target_sp) 1018 { 1019 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1020 1021 return value_sp->GetClangType(); 1022 } 1023 } 1024 return NULL; 1025} 1026 1027lldb::SBTarget 1028SBValue::GetTarget() 1029{ 1030 SBTarget sb_target; 1031 TargetSP target_sp; 1032 lldb::ValueObjectSP value_sp(GetSP()); 1033 if (value_sp) 1034 { 1035 target_sp = value_sp->GetTargetSP(); 1036 sb_target.SetSP (target_sp); 1037 } 1038 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1039 if (log) 1040 { 1041 if (target_sp.get() == NULL) 1042 log->Printf ("SBValue(%p)::GetTarget () => NULL", value_sp.get()); 1043 else 1044 log->Printf ("SBValue(%p)::GetTarget () => %p", value_sp.get(), target_sp.get()); 1045 } 1046 return sb_target; 1047} 1048 1049lldb::SBProcess 1050SBValue::GetProcess() 1051{ 1052 SBProcess sb_process; 1053 ProcessSP process_sp; 1054 lldb::ValueObjectSP value_sp(GetSP()); 1055 if (value_sp) 1056 { 1057 process_sp = value_sp->GetProcessSP(); 1058 if (process_sp) 1059 sb_process.SetSP (process_sp); 1060 } 1061 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1062 if (log) 1063 { 1064 if (process_sp.get() == NULL) 1065 log->Printf ("SBValue(%p)::GetProcess () => NULL", value_sp.get()); 1066 else 1067 log->Printf ("SBValue(%p)::GetProcess () => %p", value_sp.get(), process_sp.get()); 1068 } 1069 return sb_process; 1070} 1071 1072lldb::SBThread 1073SBValue::GetThread() 1074{ 1075 SBThread sb_thread; 1076 ThreadSP thread_sp; 1077 lldb::ValueObjectSP value_sp(GetSP()); 1078 if (value_sp) 1079 { 1080 thread_sp = value_sp->GetThreadSP(); 1081 sb_thread.SetThread(thread_sp); 1082 } 1083 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1084 if (log) 1085 { 1086 if (thread_sp.get() == NULL) 1087 log->Printf ("SBValue(%p)::GetThread () => NULL", value_sp.get()); 1088 else 1089 log->Printf ("SBValue(%p)::GetThread () => %p", value_sp.get(), thread_sp.get()); 1090 } 1091 return sb_thread; 1092} 1093 1094lldb::SBFrame 1095SBValue::GetFrame() 1096{ 1097 SBFrame sb_frame; 1098 StackFrameSP frame_sp; 1099 lldb::ValueObjectSP value_sp(GetSP()); 1100 if (value_sp) 1101 { 1102 frame_sp = value_sp->GetFrameSP(); 1103 sb_frame.SetFrameSP (frame_sp); 1104 } 1105 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1106 if (log) 1107 { 1108 if (frame_sp.get() == NULL) 1109 log->Printf ("SBValue(%p)::GetFrame () => NULL", value_sp.get()); 1110 else 1111 log->Printf ("SBValue(%p)::GetFrame () => %p", value_sp.get(), frame_sp.get()); 1112 } 1113 return sb_frame; 1114} 1115 1116 1117lldb::ValueObjectSP 1118SBValue::GetSP () const 1119{ 1120 return m_opaque_sp; 1121} 1122 1123void 1124SBValue::SetSP (const lldb::ValueObjectSP &sp) 1125{ 1126 m_opaque_sp = sp; 1127} 1128 1129 1130bool 1131SBValue::GetExpressionPath (SBStream &description) 1132{ 1133 lldb::ValueObjectSP value_sp(GetSP()); 1134 if (value_sp) 1135 { 1136 value_sp->GetExpressionPath (description.ref(), false); 1137 return true; 1138 } 1139 return false; 1140} 1141 1142bool 1143SBValue::GetExpressionPath (SBStream &description, bool qualify_cxx_base_classes) 1144{ 1145 lldb::ValueObjectSP value_sp(GetSP()); 1146 if (value_sp) 1147 { 1148 value_sp->GetExpressionPath (description.ref(), qualify_cxx_base_classes); 1149 return true; 1150 } 1151 return false; 1152} 1153 1154bool 1155SBValue::GetDescription (SBStream &description) 1156{ 1157 Stream &strm = description.ref(); 1158 1159 lldb::ValueObjectSP value_sp(GetSP()); 1160 if (value_sp) 1161 { 1162 ValueObject::DumpValueObject (strm, value_sp.get()); 1163 } 1164 else 1165 strm.PutCString ("No value"); 1166 1167 return true; 1168} 1169 1170lldb::Format 1171SBValue::GetFormat () 1172{ 1173 lldb::ValueObjectSP value_sp(GetSP()); 1174 if (value_sp) 1175 return value_sp->GetFormat(); 1176 return eFormatDefault; 1177} 1178 1179void 1180SBValue::SetFormat (lldb::Format format) 1181{ 1182 lldb::ValueObjectSP value_sp(GetSP()); 1183 if (value_sp) 1184 value_sp->SetFormat(format); 1185} 1186 1187lldb::SBValue 1188SBValue::AddressOf() 1189{ 1190 SBValue sb_value; 1191 lldb::ValueObjectSP value_sp(GetSP()); 1192 if (value_sp) 1193 { 1194 TargetSP target_sp (value_sp->GetTargetSP()); 1195 if (target_sp) 1196 { 1197 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1198 Error error; 1199 sb_value = value_sp->AddressOf (error); 1200 } 1201 } 1202 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1203 if (log) 1204 log->Printf ("SBValue(%p)::GetPointerToObject () => SBValue(%p)", value_sp.get(), value_sp.get()); 1205 1206 return sb_value; 1207} 1208 1209lldb::addr_t 1210SBValue::GetLoadAddress() 1211{ 1212 lldb::addr_t value = LLDB_INVALID_ADDRESS; 1213 lldb::ValueObjectSP value_sp(GetSP()); 1214 if (value_sp) 1215 { 1216 TargetSP target_sp (value_sp->GetTargetSP()); 1217 if (target_sp) 1218 { 1219 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1220 const bool scalar_is_load_address = true; 1221 AddressType addr_type; 1222 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type); 1223 if (addr_type == eAddressTypeFile) 1224 { 1225 ModuleSP module_sp (value_sp->GetModule()); 1226 if (!module_sp) 1227 value = LLDB_INVALID_ADDRESS; 1228 else 1229 { 1230 Address addr; 1231 module_sp->ResolveFileAddress(value, addr); 1232 value = addr.GetLoadAddress(target_sp.get()); 1233 } 1234 } 1235 else if (addr_type == eAddressTypeHost || addr_type == eAddressTypeInvalid) 1236 value = LLDB_INVALID_ADDRESS; 1237 } 1238 } 1239 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1240 if (log) 1241 log->Printf ("SBValue(%p)::GetLoadAddress () => (%llu)", value_sp.get(), value); 1242 1243 return value; 1244} 1245 1246lldb::SBAddress 1247SBValue::GetAddress() 1248{ 1249 Address addr; 1250 lldb::ValueObjectSP value_sp(GetSP()); 1251 if (value_sp) 1252 { 1253 TargetSP target_sp (value_sp->GetTargetSP()); 1254 if (target_sp) 1255 { 1256 lldb::addr_t value = LLDB_INVALID_ADDRESS; 1257 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1258 const bool scalar_is_load_address = true; 1259 AddressType addr_type; 1260 value = value_sp->GetAddressOf(scalar_is_load_address, &addr_type); 1261 if (addr_type == eAddressTypeFile) 1262 { 1263 ModuleSP module_sp (value_sp->GetModule()); 1264 if (module_sp) 1265 module_sp->ResolveFileAddress(value, addr); 1266 } 1267 else if (addr_type == eAddressTypeLoad) 1268 { 1269 // no need to check the return value on this.. if it can actually do the resolve 1270 // addr will be in the form (section,offset), otherwise it will simply be returned 1271 // as (NULL, value) 1272 addr.SetLoadAddress(value, target_sp.get()); 1273 } 1274 } 1275 } 1276 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1277 if (log) 1278 log->Printf ("SBValue(%p)::GetAddress () => (%s,%llu)", value_sp.get(), (addr.GetSection() ? addr.GetSection()->GetName().GetCString() : "NULL"), addr.GetOffset()); 1279 return SBAddress(new Address(addr)); 1280} 1281 1282lldb::SBData 1283SBValue::GetPointeeData (uint32_t item_idx, 1284 uint32_t item_count) 1285{ 1286 lldb::SBData sb_data; 1287 lldb::ValueObjectSP value_sp(GetSP()); 1288 if (value_sp) 1289 { 1290 TargetSP target_sp (value_sp->GetTargetSP()); 1291 if (target_sp) 1292 { 1293 DataExtractorSP data_sp(new DataExtractor()); 1294 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1295 value_sp->GetPointeeData(*data_sp, item_idx, item_count); 1296 if (data_sp->GetByteSize() > 0) 1297 *sb_data = data_sp; 1298 } 1299 } 1300 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1301 if (log) 1302 log->Printf ("SBValue(%p)::GetPointeeData (%d, %d) => SBData(%p)", 1303 value_sp.get(), 1304 item_idx, 1305 item_count, 1306 sb_data.get()); 1307 1308 return sb_data; 1309} 1310 1311lldb::SBData 1312SBValue::GetData () 1313{ 1314 lldb::SBData sb_data; 1315 lldb::ValueObjectSP value_sp(GetSP()); 1316 if (value_sp) 1317 { 1318 TargetSP target_sp (value_sp->GetTargetSP()); 1319 if (target_sp) 1320 { 1321 Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1322 DataExtractorSP data_sp(new DataExtractor()); 1323 value_sp->GetData(*data_sp); 1324 if (data_sp->GetByteSize() > 0) 1325 *sb_data = data_sp; 1326 } 1327 } 1328 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1329 if (log) 1330 log->Printf ("SBValue(%p)::GetData () => SBData(%p)", 1331 value_sp.get(), 1332 sb_data.get()); 1333 1334 return sb_data; 1335} 1336 1337lldb::SBWatchpoint 1338SBValue::Watch (bool resolve_location, bool read, bool write) 1339{ 1340 SBWatchpoint sb_watchpoint; 1341 1342 // If the SBValue is not valid, there's no point in even trying to watch it. 1343 lldb::ValueObjectSP value_sp(GetSP()); 1344 TargetSP target_sp (GetTarget().GetSP()); 1345 if (value_sp && target_sp) 1346 { 1347 // Read and Write cannot both be false. 1348 if (!read && !write) 1349 return sb_watchpoint; 1350 1351 // If the value is not in scope, don't try and watch and invalid value 1352 if (!IsInScope()) 1353 return sb_watchpoint; 1354 1355 addr_t addr = GetLoadAddress(); 1356 if (addr == LLDB_INVALID_ADDRESS) 1357 return sb_watchpoint; 1358 size_t byte_size = GetByteSize(); 1359 if (byte_size == 0) 1360 return sb_watchpoint; 1361 1362 uint32_t watch_type = 0; 1363 if (read) 1364 watch_type |= LLDB_WATCH_TYPE_READ; 1365 if (write) 1366 watch_type |= LLDB_WATCH_TYPE_WRITE; 1367 1368 WatchpointSP watchpoint_sp = target_sp->CreateWatchpoint(addr, byte_size, watch_type); 1369 1370 if (watchpoint_sp) 1371 { 1372 sb_watchpoint.SetSP (watchpoint_sp); 1373 Declaration decl; 1374 if (value_sp->GetDeclaration (decl)) 1375 { 1376 if (decl.GetFile()) 1377 { 1378 StreamString ss; 1379 // True to show fullpath for declaration file. 1380 decl.DumpStopContext(&ss, true); 1381 watchpoint_sp->SetDeclInfo(ss.GetString()); 1382 } 1383 } 1384 } 1385 } 1386 return sb_watchpoint; 1387} 1388 1389lldb::SBWatchpoint 1390SBValue::WatchPointee (bool resolve_location, bool read, bool write) 1391{ 1392 SBWatchpoint sb_watchpoint; 1393 if (IsInScope() && GetType().IsPointerType()) 1394 sb_watchpoint = Dereference().Watch (resolve_location, read, write); 1395 return sb_watchpoint; 1396} 1397 1398