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