1 2%extend lldb::SBAddress { 3 PyObject *lldb::SBAddress::__str__ (){ 4 lldb::SBStream description; 5 $self->GetDescription (description); 6 const char *desc = description.GetData(); 7 size_t desc_len = description.GetSize(); 8 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 9 --desc_len; 10 if (desc_len > 0) 11 return PyString_FromStringAndSize (desc, desc_len); 12 else 13 return PyString_FromString(""); 14 } 15} 16%extend lldb::SBBlock { 17 PyObject *lldb::SBBlock::__str__ (){ 18 lldb::SBStream description; 19 $self->GetDescription (description); 20 const char *desc = description.GetData(); 21 size_t desc_len = description.GetSize(); 22 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 23 --desc_len; 24 if (desc_len > 0) 25 return PyString_FromStringAndSize (desc, desc_len); 26 else 27 return PyString_FromString(""); 28 } 29} 30%extend lldb::SBBreakpoint { 31 PyObject *lldb::SBBreakpoint::__str__ (){ 32 lldb::SBStream description; 33 $self->GetDescription (description); 34 const char *desc = description.GetData(); 35 size_t desc_len = description.GetSize(); 36 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 37 --desc_len; 38 if (desc_len > 0) 39 return PyString_FromStringAndSize (desc, desc_len); 40 else 41 return PyString_FromString(""); 42 } 43 44 %pythoncode %{ 45 def __eq__(self, rhs): 46 if not isinstance(rhs, type(self)): 47 return False 48 49 return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) 50 51 def __ne__(self, rhs): 52 if not isinstance(rhs, type(self)): 53 return True 54 55 return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) 56 %} 57 58} 59%extend lldb::SBBreakpointLocation { 60 PyObject *lldb::SBBreakpointLocation::__str__ (){ 61 lldb::SBStream description; 62 $self->GetDescription (description, lldb::eDescriptionLevelFull); 63 const char *desc = description.GetData(); 64 size_t desc_len = description.GetSize(); 65 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 66 --desc_len; 67 if (desc_len > 0) 68 return PyString_FromStringAndSize (desc, desc_len); 69 else 70 return PyString_FromString(""); 71 } 72} 73 74%extend lldb::SBBroadcaster { 75 %pythoncode %{ 76 def __eq__(self, rhs): 77 if not isinstance(rhs, type(self)): 78 return False 79 80 return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) 81 82 def __ne__(self, rhs): 83 if not isinstance(rhs, type(self)): 84 return True 85 86 return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) 87 %} 88} 89 90%extend lldb::SBCommandReturnObject { 91 PyObject *lldb::SBCommandReturnObject::__str__ (){ 92 lldb::SBStream description; 93 $self->GetDescription (description); 94 const char *desc = description.GetData(); 95 size_t desc_len = description.GetSize(); 96 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 97 --desc_len; 98 if (desc_len > 0) 99 return PyString_FromStringAndSize (desc, desc_len); 100 else 101 return PyString_FromString(""); 102 } 103 104 /* the write() and flush() calls are not part of the SB API proper, and are solely for Python usage 105 they are meant to make an SBCommandReturnObject into a file-like object so that instructions of the sort 106 print >>sb_command_return_object, "something" 107 will work correctly */ 108 109 void lldb::SBCommandReturnObject::write (const char* str) 110 { 111 if (str) 112 $self->Printf("%s",str); 113 } 114 void lldb::SBCommandReturnObject::flush () 115 {} 116} 117%extend lldb::SBCompileUnit { 118 PyObject *lldb::SBCompileUnit::__str__ (){ 119 lldb::SBStream description; 120 $self->GetDescription (description); 121 const char *desc = description.GetData(); 122 size_t desc_len = description.GetSize(); 123 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 124 --desc_len; 125 if (desc_len > 0) 126 return PyString_FromStringAndSize (desc, desc_len); 127 else 128 return PyString_FromString(""); 129 } 130 %pythoncode %{ 131 def __eq__(self, rhs): 132 if not isinstance(rhs, type(self)): 133 return False 134 135 return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) 136 137 def __ne__(self, rhs): 138 if not isinstance(rhs, type(self)): 139 return True 140 141 return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) 142 %} 143} 144%extend lldb::SBData { 145 PyObject *lldb::SBData::__str__ (){ 146 lldb::SBStream description; 147 $self->GetDescription (description); 148 const char *desc = description.GetData(); 149 size_t desc_len = description.GetSize(); 150 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 151 --desc_len; 152 if (desc_len > 0) 153 return PyString_FromStringAndSize (desc, desc_len); 154 else 155 return PyString_FromString(""); 156 } 157} 158%extend lldb::SBDebugger { 159 PyObject *lldb::SBDebugger::__str__ (){ 160 lldb::SBStream description; 161 $self->GetDescription (description); 162 const char *desc = description.GetData(); 163 size_t desc_len = description.GetSize(); 164 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 165 --desc_len; 166 if (desc_len > 0) 167 return PyString_FromStringAndSize (desc, desc_len); 168 else 169 return PyString_FromString(""); 170 } 171} 172%extend lldb::SBDeclaration { 173 PyObject *lldb::SBDeclaration::__str__ (){ 174 lldb::SBStream description; 175 $self->GetDescription (description); 176 const char *desc = description.GetData(); 177 size_t desc_len = description.GetSize(); 178 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 179 --desc_len; 180 if (desc_len > 0) 181 return PyString_FromStringAndSize (desc, desc_len); 182 else 183 return PyString_FromString(""); 184 } 185 186 %pythoncode %{ 187 def __eq__(self, rhs): 188 if not isinstance(rhs, type(self)): 189 return False 190 191 return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) 192 193 def __ne__(self, rhs): 194 if not isinstance(rhs, type(self)): 195 return True 196 197 return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) 198 %} 199 200} 201%extend lldb::SBError { 202 PyObject *lldb::SBError::__str__ (){ 203 lldb::SBStream description; 204 $self->GetDescription (description); 205 const char *desc = description.GetData(); 206 size_t desc_len = description.GetSize(); 207 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 208 --desc_len; 209 if (desc_len > 0) 210 return PyString_FromStringAndSize (desc, desc_len); 211 else 212 return PyString_FromString(""); 213 } 214} 215%extend lldb::SBFileSpec { 216 PyObject *lldb::SBFileSpec::__str__ (){ 217 lldb::SBStream description; 218 $self->GetDescription (description); 219 const char *desc = description.GetData(); 220 size_t desc_len = description.GetSize(); 221 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 222 --desc_len; 223 if (desc_len > 0) 224 return PyString_FromStringAndSize (desc, desc_len); 225 else 226 return PyString_FromString(""); 227 } 228} 229%extend lldb::SBFrame { 230 PyObject *lldb::SBFrame::__str__ (){ 231 lldb::SBStream description; 232 $self->GetDescription (description); 233 const char *desc = description.GetData(); 234 size_t desc_len = description.GetSize(); 235 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 236 --desc_len; 237 if (desc_len > 0) 238 return PyString_FromStringAndSize (desc, desc_len); 239 else 240 return PyString_FromString(""); 241 } 242} 243%extend lldb::SBFunction { 244 PyObject *lldb::SBFunction::__str__ (){ 245 lldb::SBStream description; 246 $self->GetDescription (description); 247 const char *desc = description.GetData(); 248 size_t desc_len = description.GetSize(); 249 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 250 --desc_len; 251 if (desc_len > 0) 252 return PyString_FromStringAndSize (desc, desc_len); 253 else 254 return PyString_FromString(""); 255 } 256 257 %pythoncode %{ 258 def __eq__(self, rhs): 259 if not isinstance(rhs, type(self)): 260 return False 261 262 return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) 263 264 def __ne__(self, rhs): 265 if not isinstance(rhs, type(self)): 266 return True 267 268 return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) 269 %} 270 271} 272%extend lldb::SBInstruction { 273 PyObject *lldb::SBInstruction::__str__ (){ 274 lldb::SBStream description; 275 $self->GetDescription (description); 276 const char *desc = description.GetData(); 277 size_t desc_len = description.GetSize(); 278 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 279 --desc_len; 280 if (desc_len > 0) 281 return PyString_FromStringAndSize (desc, desc_len); 282 else 283 return PyString_FromString(""); 284 } 285} 286%extend lldb::SBInstructionList { 287 PyObject *lldb::SBInstructionList::__str__ (){ 288 lldb::SBStream description; 289 $self->GetDescription (description); 290 const char *desc = description.GetData(); 291 size_t desc_len = description.GetSize(); 292 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 293 --desc_len; 294 if (desc_len > 0) 295 return PyString_FromStringAndSize (desc, desc_len); 296 else 297 return PyString_FromString(""); 298 } 299} 300%extend lldb::SBLineEntry { 301 PyObject *lldb::SBLineEntry::__str__ (){ 302 lldb::SBStream description; 303 $self->GetDescription (description); 304 const char *desc = description.GetData(); 305 size_t desc_len = description.GetSize(); 306 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 307 --desc_len; 308 if (desc_len > 0) 309 return PyString_FromStringAndSize (desc, desc_len); 310 else 311 return PyString_FromString(""); 312 } 313 314 %pythoncode %{ 315 def __eq__(self, rhs): 316 if not isinstance(rhs, type(self)): 317 return False 318 319 return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) 320 321 def __ne__(self, rhs): 322 if not isinstance(rhs, type(self)): 323 return True 324 325 return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) 326 %} 327} 328%extend lldb::SBModule { 329 PyObject *lldb::SBModule::__str__ (){ 330 lldb::SBStream description; 331 $self->GetDescription (description); 332 const char *desc = description.GetData(); 333 size_t desc_len = description.GetSize(); 334 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 335 --desc_len; 336 if (desc_len > 0) 337 return PyString_FromStringAndSize (desc, desc_len); 338 else 339 return PyString_FromString(""); 340 } 341 342 %pythoncode %{ 343 def __eq__(self, rhs): 344 if not isinstance(rhs, type(self)): 345 return False 346 347 return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) 348 349 def __ne__(self, rhs): 350 if not isinstance(rhs, type(self)): 351 return True 352 353 return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) 354 %} 355} 356 357%extend lldb::SBModuleSpec { 358 PyObject *lldb::SBModuleSpec::__str__ (){ 359 lldb::SBStream description; 360 $self->GetDescription (description); 361 const char *desc = description.GetData(); 362 size_t desc_len = description.GetSize(); 363 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 364 --desc_len; 365 if (desc_len > 0) 366 return PyString_FromStringAndSize (desc, desc_len); 367 else 368 return PyString_FromString(""); 369 } 370} 371 372%extend lldb::SBModuleSpecList { 373 PyObject *lldb::SBModuleSpecList::__str__ (){ 374 lldb::SBStream description; 375 $self->GetDescription (description); 376 const char *desc = description.GetData(); 377 size_t desc_len = description.GetSize(); 378 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 379 --desc_len; 380 if (desc_len > 0) 381 return PyString_FromStringAndSize (desc, desc_len); 382 else 383 return PyString_FromString(""); 384 } 385} 386 387%extend lldb::SBProcess { 388 PyObject *lldb::SBProcess::__str__ (){ 389 lldb::SBStream description; 390 $self->GetDescription (description); 391 const char *desc = description.GetData(); 392 size_t desc_len = description.GetSize(); 393 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 394 --desc_len; 395 if (desc_len > 0) 396 return PyString_FromStringAndSize (desc, desc_len); 397 else 398 return PyString_FromString(""); 399 } 400} 401%extend lldb::SBSection { 402 PyObject *lldb::SBSection::__str__ (){ 403 lldb::SBStream description; 404 $self->GetDescription (description); 405 const char *desc = description.GetData(); 406 size_t desc_len = description.GetSize(); 407 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 408 --desc_len; 409 if (desc_len > 0) 410 return PyString_FromStringAndSize (desc, desc_len); 411 else 412 return PyString_FromString(""); 413 } 414 415 %pythoncode %{ 416 def __eq__(self, rhs): 417 if not isinstance(rhs, type(self)): 418 return False 419 420 return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) 421 422 def __ne__(self, rhs): 423 if not isinstance(rhs, type(self)): 424 return True 425 426 return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) 427 %} 428} 429%extend lldb::SBStream { 430 /* the write() and flush() calls are not part of the SB API proper, and are solely for Python usage 431 they are meant to make an SBStream into a file-like object so that instructions of the sort 432 print >>sb_stream, "something" 433 will work correctly */ 434 435 void lldb::SBStream::write (const char* str) 436 { 437 if (str) 438 $self->Printf("%s",str); 439 } 440 void lldb::SBStream::flush () 441 {} 442} 443%extend lldb::SBSymbol { 444 PyObject *lldb::SBSymbol::__str__ (){ 445 lldb::SBStream description; 446 $self->GetDescription (description); 447 const char *desc = description.GetData(); 448 size_t desc_len = description.GetSize(); 449 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 450 --desc_len; 451 if (desc_len > 0) 452 return PyString_FromStringAndSize (desc, desc_len); 453 else 454 return PyString_FromString(""); 455 } 456 %pythoncode %{ 457 def __eq__(self, rhs): 458 if not isinstance(rhs, type(self)): 459 return False 460 461 return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) 462 463 def __ne__(self, rhs): 464 if not isinstance(rhs, type(self)): 465 return True 466 467 return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) 468 %} 469} 470%extend lldb::SBSymbolContext { 471 PyObject *lldb::SBSymbolContext::__str__ (){ 472 lldb::SBStream description; 473 $self->GetDescription (description); 474 const char *desc = description.GetData(); 475 size_t desc_len = description.GetSize(); 476 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 477 --desc_len; 478 if (desc_len > 0) 479 return PyString_FromStringAndSize (desc, desc_len); 480 else 481 return PyString_FromString(""); 482 } 483} 484%extend lldb::SBSymbolContextList { 485 PyObject *lldb::SBSymbolContextList::__str__ (){ 486 lldb::SBStream description; 487 $self->GetDescription (description); 488 const char *desc = description.GetData(); 489 size_t desc_len = description.GetSize(); 490 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 491 --desc_len; 492 if (desc_len > 0) 493 return PyString_FromStringAndSize (desc, desc_len); 494 else 495 return PyString_FromString(""); 496 } 497} 498 499%extend lldb::SBTarget { 500 PyObject *lldb::SBTarget::__str__ (){ 501 lldb::SBStream description; 502 $self->GetDescription (description, lldb::eDescriptionLevelBrief); 503 const char *desc = description.GetData(); 504 size_t desc_len = description.GetSize(); 505 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 506 --desc_len; 507 if (desc_len > 0) 508 return PyString_FromStringAndSize (desc, desc_len); 509 else 510 return PyString_FromString(""); 511 } 512 513 %pythoncode %{ 514 def __eq__(self, rhs): 515 if not isinstance(rhs, type(self)): 516 return False 517 518 return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) 519 520 def __ne__(self, rhs): 521 if not isinstance(rhs, type(self)): 522 return True 523 524 return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) 525 %} 526} 527 528%extend lldb::SBType { 529 PyObject *lldb::SBType::__str__ (){ 530 lldb::SBStream description; 531 $self->GetDescription (description, lldb::eDescriptionLevelBrief); 532 const char *desc = description.GetData(); 533 size_t desc_len = description.GetSize(); 534 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 535 --desc_len; 536 if (desc_len > 0) 537 return PyString_FromStringAndSize (desc, desc_len); 538 else 539 return PyString_FromString(""); 540 } 541} 542%extend lldb::SBTypeCategory { 543 PyObject *lldb::SBTypeCategory::__str__ (){ 544 lldb::SBStream description; 545 $self->GetDescription (description, lldb::eDescriptionLevelBrief); 546 const char *desc = description.GetData(); 547 size_t desc_len = description.GetSize(); 548 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 549 --desc_len; 550 if (desc_len > 0) 551 return PyString_FromStringAndSize (desc, desc_len); 552 else 553 return PyString_FromString(""); 554 } 555} 556%extend lldb::SBTypeFilter { 557 PyObject *lldb::SBTypeFilter::__str__ (){ 558 lldb::SBStream description; 559 $self->GetDescription (description, lldb::eDescriptionLevelBrief); 560 const char *desc = description.GetData(); 561 size_t desc_len = description.GetSize(); 562 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 563 --desc_len; 564 if (desc_len > 0) 565 return PyString_FromStringAndSize (desc, desc_len); 566 else 567 return PyString_FromString(""); 568 } 569 %pythoncode %{ 570 def __eq__(self, rhs): 571 if not isinstance(rhs, type(self)): 572 return False 573 574 return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) 575 576 def __ne__(self, rhs): 577 if not isinstance(rhs, type(self)): 578 return True 579 580 return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) 581 %} 582} 583%extend lldb::SBTypeFormat { 584 PyObject *lldb::SBTypeFormat::__str__ (){ 585 lldb::SBStream description; 586 $self->GetDescription (description, lldb::eDescriptionLevelBrief); 587 const char *desc = description.GetData(); 588 size_t desc_len = description.GetSize(); 589 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 590 --desc_len; 591 if (desc_len > 0) 592 return PyString_FromStringAndSize (desc, desc_len); 593 else 594 return PyString_FromString(""); 595 } 596} 597%extend lldb::SBTypeMember { 598 PyObject *lldb::SBTypeMember::__str__ (){ 599 lldb::SBStream description; 600 $self->GetDescription (description, lldb::eDescriptionLevelBrief); 601 const char *desc = description.GetData(); 602 size_t desc_len = description.GetSize(); 603 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 604 --desc_len; 605 if (desc_len > 0) 606 return PyString_FromStringAndSize (desc, desc_len); 607 else 608 return PyString_FromString(""); 609 } 610} 611%extend lldb::SBTypeNameSpecifier { 612 PyObject *lldb::SBTypeNameSpecifier::__str__ (){ 613 lldb::SBStream description; 614 $self->GetDescription (description, lldb::eDescriptionLevelBrief); 615 const char *desc = description.GetData(); 616 size_t desc_len = description.GetSize(); 617 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 618 --desc_len; 619 if (desc_len > 0) 620 return PyString_FromStringAndSize (desc, desc_len); 621 else 622 return PyString_FromString(""); 623 } 624 %pythoncode %{ 625 def __eq__(self, rhs): 626 if not isinstance(rhs, type(self)): 627 return False 628 629 return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) 630 631 def __ne__(self, rhs): 632 if not isinstance(rhs, type(self)): 633 return True 634 635 return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) 636 %} 637} 638%extend lldb::SBTypeSummary { 639 PyObject *lldb::SBTypeSummary::__str__ (){ 640 lldb::SBStream description; 641 $self->GetDescription (description, lldb::eDescriptionLevelBrief); 642 const char *desc = description.GetData(); 643 size_t desc_len = description.GetSize(); 644 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 645 --desc_len; 646 if (desc_len > 0) 647 return PyString_FromStringAndSize (desc, desc_len); 648 else 649 return PyString_FromString(""); 650 } 651 %pythoncode %{ 652 def __eq__(self, rhs): 653 if not isinstance(rhs, type(self)): 654 return False 655 656 return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) 657 658 def __ne__(self, rhs): 659 if not isinstance(rhs, type(self)): 660 return True 661 662 return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) 663 %} 664} 665%extend lldb::SBTypeSynthetic { 666 PyObject *lldb::SBTypeSynthetic::__str__ (){ 667 lldb::SBStream description; 668 $self->GetDescription (description, lldb::eDescriptionLevelBrief); 669 const char *desc = description.GetData(); 670 size_t desc_len = description.GetSize(); 671 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 672 --desc_len; 673 if (desc_len > 0) 674 return PyString_FromStringAndSize (desc, desc_len); 675 else 676 return PyString_FromString(""); 677 } 678 %pythoncode %{ 679 def __eq__(self, rhs): 680 if not isinstance(rhs, type(self)): 681 return False 682 683 return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) 684 685 def __ne__(self, rhs): 686 if not isinstance(rhs, type(self)): 687 return True 688 689 return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) 690 %} 691} 692%extend lldb::SBThread { 693 PyObject *lldb::SBThread::__str__ (){ 694 lldb::SBStream description; 695 $self->GetDescription (description); 696 const char *desc = description.GetData(); 697 size_t desc_len = description.GetSize(); 698 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 699 --desc_len; 700 if (desc_len > 0) 701 return PyString_FromStringAndSize (desc, desc_len); 702 else 703 return PyString_FromString(""); 704 } 705 %pythoncode %{ 706 def __eq__(self, rhs): 707 if not isinstance(rhs, type(self)): 708 return False 709 710 return getattr(_lldb,self.__class__.__name__+"___eq__")(self, rhs) 711 712 def __ne__(self, rhs): 713 if not isinstance(rhs, type(self)): 714 return True 715 716 return getattr(_lldb,self.__class__.__name__+"___ne__")(self, rhs) 717 %} 718} 719%extend lldb::SBValue { 720 PyObject *lldb::SBValue::__str__ (){ 721 lldb::SBStream description; 722 $self->GetDescription (description); 723 const char *desc = description.GetData(); 724 size_t desc_len = description.GetSize(); 725 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 726 --desc_len; 727 if (desc_len > 0) 728 return PyString_FromStringAndSize (desc, desc_len); 729 else 730 return PyString_FromString(""); 731 } 732} 733%extend lldb::SBValueList { 734 PyObject *lldb::SBValueList::__str__ (){ 735 lldb::SBStream description; 736 const size_t n = $self->GetSize(); 737 if (n) 738 { 739 for (size_t i=0; i<n; ++i) 740 $self->GetValueAtIndex(i).GetDescription(description); 741 } 742 else 743 { 744 description.Printf("<empty> lldb.SBValueList()"); 745 } 746 const char *desc = description.GetData(); 747 size_t desc_len = description.GetSize(); 748 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 749 --desc_len; 750 if (desc_len > 0) 751 return PyString_FromStringAndSize (desc, desc_len); 752 else 753 return PyString_FromString(""); 754 } 755} 756%extend lldb::SBWatchpoint { 757 PyObject *lldb::SBWatchpoint::__str__ (){ 758 lldb::SBStream description; 759 $self->GetDescription (description, lldb::eDescriptionLevelVerbose); 760 const char *desc = description.GetData(); 761 size_t desc_len = description.GetSize(); 762 if (desc_len > 0 && (desc[desc_len-1] == '\n' || desc[desc_len-1] == '\r')) 763 --desc_len; 764 if (desc_len > 0) 765 return PyString_FromStringAndSize (desc, desc_len); 766 else 767 return PyString_FromString(""); 768 } 769} 770 771 772// %extend lldb::SBDebugger { 773// // FIXME: We can't get the callback and baton 774// PyObject *lldb::SBDebugger (){ 775// // Only call Py_XDECREF if we have a Python object (or NULL) 776// if (LLDBSwigPythonCallPythonLogOutputCallback == $self->GetLogOutPutCallback()) 777// Py_XDECREF($self->GetCallbackBaton()); 778// } 779// } 780// %extend lldb::SBInputReader { 781// // FIXME: m_callback_function is private and we have no other 782// // way to access it. 783// PyObject *lldb::SBInputReader::__del__ (){ 784// // Only call Py_XDECREF if we have a Python object (or NULL) 785// if (LLDBSwigPythonCallSBInputReaderCallback == $self->m_callback_function) 786// Py_XDECREF($self->m_callback_baton); 787// } 788// } 789 790%pythoncode %{ 791 792def command(*args, **kwargs): 793 import lldb 794 """A decorator function that registers an LLDB command line 795 command that is bound to the function it is attached to.""" 796 class obj(object): 797 """The object that tracks adding the command to LLDB one time and handles 798 calling the function on subsequent calls.""" 799 def __init__(self, function, command_name, doc = None): 800 if doc: 801 function.__doc__ = doc 802 command = "command script add -f %s.%s %s" % (function.__module__, function.__name__, command_name) 803 lldb.debugger.HandleCommand(command) 804 self.function = function 805 def __call__(self, *args, **kwargs): 806 self.function(*args, **kwargs) 807 def callable(function): 808 """Creates a callable object that gets used.""" 809 return obj(function, *args, **kwargs) 810 return callable 811 812class declaration(object): 813 '''A class that represents a source declaration location with file, line and column.''' 814 def __init__(self, file, line, col): 815 self.file = file 816 self.line = line 817 self.col = col 818 819class value_iter(object): 820 def __iter__(self): 821 return self 822 823 def next(self): 824 if self.index >= self.length: 825 raise StopIteration() 826 child_sbvalue = self.sbvalue.GetChildAtIndex(self.index) 827 self.index += 1 828 return value(child_sbvalue) 829 830 def __init__(self,value): 831 self.index = 0 832 self.sbvalue = value 833 if type(self.sbvalue) is value: 834 self.sbvalue = self.sbvalue.sbvalue 835 self.length = self.sbvalue.GetNumChildren() 836 837class value(object): 838 '''A class designed to wrap lldb.SBValue() objects so the resulting object 839 can be used as a variable would be in code. So if you have a Point structure 840 variable in your code in the current frame named "pt", you can initialize an instance 841 of this class with it: 842 843 pt = lldb.value(lldb.frame.FindVariable("pt")) 844 print pt 845 print pt.x 846 print pt.y 847 848 pt = lldb.value(lldb.frame.FindVariable("rectangle_array")) 849 print rectangle_array[12] 850 print rectangle_array[5].origin.x''' 851 def __init__(self, sbvalue): 852 self.sbvalue = sbvalue 853 854 def __nonzero__(self): 855 return self.sbvalue.__nonzero__() 856 857 def __str__(self): 858 return self.sbvalue.__str__() 859 860 def __getitem__(self, key): 861 # Allow array access if this value has children... 862 if type(key) is value: 863 key = int(key) 864 if type(key) is int: 865 child_sbvalue = (self.sbvalue.GetValueForExpressionPath("[%i]" % key)) 866 if child_sbvalue and child_sbvalue.IsValid(): 867 return value(child_sbvalue) 868 raise IndexError("Index '%d' is out of range" % key) 869 raise TypeError("No array item of type %s" % str(type(key))) 870 871 def __iter__(self): 872 return value_iter(self.sbvalue) 873 874 def __getattr__(self, name): 875 child_sbvalue = self.sbvalue.GetChildMemberWithName (name) 876 if child_sbvalue and child_sbvalue.IsValid(): 877 return value(child_sbvalue) 878 raise AttributeError("Attribute '%s' is not defined" % name) 879 880 def __add__(self, other): 881 return int(self) + int(other) 882 883 def __sub__(self, other): 884 return int(self) - int(other) 885 886 def __mul__(self, other): 887 return int(self) * int(other) 888 889 def __floordiv__(self, other): 890 return int(self) // int(other) 891 892 def __mod__(self, other): 893 return int(self) % int(other) 894 895 def __divmod__(self, other): 896 return int(self) % int(other) 897 898 def __pow__(self, other): 899 return int(self) ** int(other) 900 901 def __lshift__(self, other): 902 return int(self) << int(other) 903 904 def __rshift__(self, other): 905 return int(self) >> int(other) 906 907 def __and__(self, other): 908 return int(self) & int(other) 909 910 def __xor__(self, other): 911 return int(self) ^ int(other) 912 913 def __or__(self, other): 914 return int(self) | int(other) 915 916 def __div__(self, other): 917 return int(self) / int(other) 918 919 def __truediv__(self, other): 920 return int(self) / int(other) 921 922 def __iadd__(self, other): 923 result = self.__add__(other) 924 self.sbvalue.SetValueFromCString (str(result)) 925 return result 926 927 def __isub__(self, other): 928 result = self.__sub__(other) 929 self.sbvalue.SetValueFromCString (str(result)) 930 return result 931 932 def __imul__(self, other): 933 result = self.__mul__(other) 934 self.sbvalue.SetValueFromCString (str(result)) 935 return result 936 937 def __idiv__(self, other): 938 result = self.__div__(other) 939 self.sbvalue.SetValueFromCString (str(result)) 940 return result 941 942 def __itruediv__(self, other): 943 result = self.__truediv__(other) 944 self.sbvalue.SetValueFromCString (str(result)) 945 return result 946 947 def __ifloordiv__(self, other): 948 result = self.__floordiv__(self, other) 949 self.sbvalue.SetValueFromCString (str(result)) 950 return result 951 952 def __imod__(self, other): 953 result = self.__and__(self, other) 954 self.sbvalue.SetValueFromCString (str(result)) 955 return result 956 957 def __ipow__(self, other): 958 result = self.__pow__(self, other) 959 self.sbvalue.SetValueFromCString (str(result)) 960 return result 961 962 def __ipow__(self, other, modulo): 963 result = self.__pow__(self, other, modulo) 964 self.sbvalue.SetValueFromCString (str(result)) 965 return result 966 967 def __ilshift__(self, other): 968 result = self.__lshift__(other) 969 self.sbvalue.SetValueFromCString (str(result)) 970 return result 971 972 def __irshift__(self, other): 973 result = self.__rshift__(other) 974 self.sbvalue.SetValueFromCString (str(result)) 975 return result 976 977 def __iand__(self, other): 978 result = self.__and__(self, other) 979 self.sbvalue.SetValueFromCString (str(result)) 980 return result 981 982 def __ixor__(self, other): 983 result = self.__xor__(self, other) 984 self.sbvalue.SetValueFromCString (str(result)) 985 return result 986 987 def __ior__(self, other): 988 result = self.__ior__(self, other) 989 self.sbvalue.SetValueFromCString (str(result)) 990 return result 991 992 def __neg__(self): 993 return -int(self) 994 995 def __pos__(self): 996 return +int(self) 997 998 def __abs__(self): 999 return abs(int(self)) 1000 1001 def __invert__(self): 1002 return ~int(self) 1003 1004 def __complex__(self): 1005 return complex (int(self)) 1006 1007 def __int__(self): 1008 return self.sbvalue.GetValueAsSigned() 1009 1010 def __long__(self): 1011 return self.sbvalue.GetValueAsSigned() 1012 1013 def __float__(self): 1014 return float (self.sbvalue.GetValueAsSigned()) 1015 1016 def __oct__(self): 1017 return '0%o' % self.sbvalue.GetValueAsUnsigned() 1018 1019 def __hex__(self): 1020 return '0x%x' % self.sbvalue.GetValueAsUnsigned() 1021 1022 def __len__(self): 1023 return self.sbvalue.GetNumChildren() 1024 1025 def __eq__(self, other): 1026 if type(other) is int: 1027 return int(self) == other 1028 elif type(other) is str: 1029 return str(self) == other 1030 elif type(other) is value: 1031 self_err = SBError() 1032 other_err = SBError() 1033 self_val = self.sbvalue.GetValueAsUnsigned(self_err) 1034 if self_err.fail: 1035 raise ValueError("unable to extract value of self") 1036 other_val = other.sbvalue.GetValueAsUnsigned(other_err) 1037 if other_err.fail: 1038 raise ValueError("unable to extract value of other") 1039 return self_val == other_val 1040 raise TypeError("Unknown type %s, No equality operation defined." % str(type(other))) 1041 1042 def __neq__(self, other): 1043 return not self.__eq__(other) 1044%} 1045