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