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