1 1.1 christos /* Python interface to blocks. 2 1.1 christos 3 1.11 christos Copyright (C) 2008-2024 Free Software Foundation, Inc. 4 1.1 christos 5 1.1 christos This file is part of GDB. 6 1.1 christos 7 1.1 christos This program is free software; you can redistribute it and/or modify 8 1.1 christos it under the terms of the GNU General Public License as published by 9 1.1 christos the Free Software Foundation; either version 3 of the License, or 10 1.1 christos (at your option) any later version. 11 1.1 christos 12 1.1 christos This program is distributed in the hope that it will be useful, 13 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 14 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 1.1 christos GNU General Public License for more details. 16 1.1 christos 17 1.1 christos You should have received a copy of the GNU General Public License 18 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 19 1.1 christos 20 1.1 christos #include "block.h" 21 1.1 christos #include "dictionary.h" 22 1.1 christos #include "symtab.h" 23 1.1 christos #include "python-internal.h" 24 1.1 christos #include "objfiles.h" 25 1.1 christos 26 1.10 christos struct block_object { 27 1.1 christos PyObject_HEAD 28 1.1 christos /* The GDB block structure that represents a frame's code block. */ 29 1.1 christos const struct block *block; 30 1.1 christos /* The backing object file. There is no direct relationship in GDB 31 1.1 christos between a block and an object file. When a block is created also 32 1.1 christos store a pointer to the object file for later use. */ 33 1.1 christos struct objfile *objfile; 34 1.10 christos }; 35 1.1 christos 36 1.10 christos struct block_syms_iterator_object { 37 1.1 christos PyObject_HEAD 38 1.1 christos /* The block. */ 39 1.1 christos const struct block *block; 40 1.1 christos /* The iterator for that block. */ 41 1.1 christos struct block_iterator iter; 42 1.1 christos /* Has the iterator been initialized flag. */ 43 1.1 christos int initialized_p; 44 1.1 christos /* Pointer back to the original source block object. Needed to 45 1.1 christos check if the block is still valid, and has not been invalidated 46 1.1 christos when an object file has been freed. */ 47 1.10 christos block_object *source; 48 1.10 christos }; 49 1.1 christos 50 1.1 christos /* Require a valid block. All access to block_object->block should be 51 1.1 christos gated by this call. */ 52 1.1 christos #define BLPY_REQUIRE_VALID(block_obj, block) \ 53 1.1 christos do { \ 54 1.1 christos block = block_object_to_block (block_obj); \ 55 1.1 christos if (block == NULL) \ 56 1.1 christos { \ 57 1.1 christos PyErr_SetString (PyExc_RuntimeError, \ 58 1.1 christos _("Block is invalid.")); \ 59 1.1 christos return NULL; \ 60 1.1 christos } \ 61 1.1 christos } while (0) 62 1.1 christos 63 1.1 christos /* Require a valid block. This macro is called during block iterator 64 1.1 christos creation, and at each next call. */ 65 1.1 christos #define BLPY_ITER_REQUIRE_VALID(block_obj) \ 66 1.1 christos do { \ 67 1.1 christos if (block_obj->block == NULL) \ 68 1.1 christos { \ 69 1.1 christos PyErr_SetString (PyExc_RuntimeError, \ 70 1.1 christos _("Source block for iterator is invalid.")); \ 71 1.1 christos return NULL; \ 72 1.1 christos } \ 73 1.1 christos } while (0) 74 1.1 christos 75 1.5 christos extern PyTypeObject block_syms_iterator_object_type 76 1.1 christos CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("block_syms_iterator_object"); 77 1.12 christos static const registry<objfile>::key<htab, htab_deleter> 78 1.10 christos blpy_objfile_data_key; 79 1.1 christos 80 1.1 christos static PyObject * 81 1.1 christos blpy_iter (PyObject *self) 82 1.1 christos { 83 1.1 christos block_syms_iterator_object *block_iter_obj; 84 1.1 christos const struct block *block = NULL; 85 1.1 christos 86 1.1 christos BLPY_REQUIRE_VALID (self, block); 87 1.1 christos 88 1.1 christos block_iter_obj = PyObject_New (block_syms_iterator_object, 89 1.1 christos &block_syms_iterator_object_type); 90 1.1 christos if (block_iter_obj == NULL) 91 1.1 christos return NULL; 92 1.1 christos 93 1.1 christos block_iter_obj->block = block; 94 1.1 christos block_iter_obj->initialized_p = 0; 95 1.1 christos Py_INCREF (self); 96 1.1 christos block_iter_obj->source = (block_object *) self; 97 1.1 christos 98 1.1 christos return (PyObject *) block_iter_obj; 99 1.1 christos } 100 1.1 christos 101 1.1 christos static PyObject * 102 1.1 christos blpy_get_start (PyObject *self, void *closure) 103 1.1 christos { 104 1.1 christos const struct block *block = NULL; 105 1.1 christos 106 1.1 christos BLPY_REQUIRE_VALID (self, block); 107 1.1 christos 108 1.10 christos return gdb_py_object_from_ulongest (block->start ()).release (); 109 1.1 christos } 110 1.1 christos 111 1.1 christos static PyObject * 112 1.1 christos blpy_get_end (PyObject *self, void *closure) 113 1.1 christos { 114 1.1 christos const struct block *block = NULL; 115 1.1 christos 116 1.1 christos BLPY_REQUIRE_VALID (self, block); 117 1.1 christos 118 1.10 christos return gdb_py_object_from_ulongest (block->end ()).release (); 119 1.1 christos } 120 1.1 christos 121 1.1 christos static PyObject * 122 1.1 christos blpy_get_function (PyObject *self, void *closure) 123 1.1 christos { 124 1.1 christos struct symbol *sym; 125 1.1 christos const struct block *block; 126 1.1 christos 127 1.1 christos BLPY_REQUIRE_VALID (self, block); 128 1.1 christos 129 1.10 christos sym = block->function (); 130 1.1 christos if (sym) 131 1.1 christos return symbol_to_symbol_object (sym); 132 1.1 christos 133 1.1 christos Py_RETURN_NONE; 134 1.1 christos } 135 1.1 christos 136 1.1 christos static PyObject * 137 1.1 christos blpy_get_superblock (PyObject *self, void *closure) 138 1.1 christos { 139 1.1 christos const struct block *block; 140 1.1 christos const struct block *super_block; 141 1.1 christos block_object *self_obj = (block_object *) self; 142 1.1 christos 143 1.1 christos BLPY_REQUIRE_VALID (self, block); 144 1.1 christos 145 1.10 christos super_block = block->superblock (); 146 1.1 christos if (super_block) 147 1.1 christos return block_to_block_object (super_block, self_obj->objfile); 148 1.1 christos 149 1.1 christos Py_RETURN_NONE; 150 1.1 christos } 151 1.1 christos 152 1.1 christos /* Return the global block associated to this block. */ 153 1.1 christos 154 1.1 christos static PyObject * 155 1.1 christos blpy_get_global_block (PyObject *self, void *closure) 156 1.1 christos { 157 1.1 christos const struct block *block; 158 1.1 christos const struct block *global_block; 159 1.1 christos block_object *self_obj = (block_object *) self; 160 1.1 christos 161 1.1 christos BLPY_REQUIRE_VALID (self, block); 162 1.1 christos 163 1.11 christos global_block = block->global_block (); 164 1.1 christos 165 1.1 christos return block_to_block_object (global_block, 166 1.1 christos self_obj->objfile); 167 1.1 christos 168 1.1 christos } 169 1.1 christos 170 1.1 christos /* Return the static block associated to this block. Return None 171 1.1 christos if we cannot get the static block (this is the global block). */ 172 1.1 christos 173 1.1 christos static PyObject * 174 1.1 christos blpy_get_static_block (PyObject *self, void *closure) 175 1.1 christos { 176 1.1 christos const struct block *block; 177 1.1 christos const struct block *static_block; 178 1.1 christos block_object *self_obj = (block_object *) self; 179 1.1 christos 180 1.1 christos BLPY_REQUIRE_VALID (self, block); 181 1.1 christos 182 1.10 christos if (block->superblock () == NULL) 183 1.1 christos Py_RETURN_NONE; 184 1.1 christos 185 1.11 christos static_block = block->static_block (); 186 1.1 christos 187 1.1 christos return block_to_block_object (static_block, self_obj->objfile); 188 1.1 christos } 189 1.1 christos 190 1.1 christos /* Implementation of gdb.Block.is_global (self) -> Boolean. 191 1.1 christos Returns True if this block object is a global block. */ 192 1.1 christos 193 1.1 christos static PyObject * 194 1.1 christos blpy_is_global (PyObject *self, void *closure) 195 1.1 christos { 196 1.1 christos const struct block *block; 197 1.1 christos 198 1.1 christos BLPY_REQUIRE_VALID (self, block); 199 1.1 christos 200 1.10 christos if (block->superblock ()) 201 1.1 christos Py_RETURN_FALSE; 202 1.1 christos 203 1.1 christos Py_RETURN_TRUE; 204 1.1 christos } 205 1.1 christos 206 1.1 christos /* Implementation of gdb.Block.is_static (self) -> Boolean. 207 1.1 christos Returns True if this block object is a static block. */ 208 1.1 christos 209 1.1 christos static PyObject * 210 1.1 christos blpy_is_static (PyObject *self, void *closure) 211 1.1 christos { 212 1.1 christos const struct block *block; 213 1.1 christos 214 1.1 christos BLPY_REQUIRE_VALID (self, block); 215 1.1 christos 216 1.10 christos if (block->superblock () != NULL 217 1.10 christos && block->superblock ()->superblock () == NULL) 218 1.1 christos Py_RETURN_TRUE; 219 1.1 christos 220 1.1 christos Py_RETURN_FALSE; 221 1.1 christos } 222 1.1 christos 223 1.9 christos /* Given a string, returns the gdb.Symbol representing that symbol in this 224 1.9 christos block. If such a symbol does not exist, returns NULL with a Python 225 1.9 christos exception. */ 226 1.9 christos 227 1.9 christos static PyObject * 228 1.9 christos blpy_getitem (PyObject *self, PyObject *key) 229 1.9 christos { 230 1.9 christos const struct block *block; 231 1.9 christos 232 1.9 christos BLPY_REQUIRE_VALID (self, block); 233 1.9 christos 234 1.9 christos gdb::unique_xmalloc_ptr<char> name = python_string_to_host_string (key); 235 1.9 christos if (name == nullptr) 236 1.9 christos return nullptr; 237 1.9 christos 238 1.9 christos lookup_name_info lookup_name (name.get(), symbol_name_match_type::FULL); 239 1.9 christos 240 1.11 christos /* We use an iterator instead of block_lookup_symbol so that we can 241 1.11 christos look up symbols irrespective of the domain, matching the 242 1.11 christos iterator. It would be confusing if the iterator returns symbols 243 1.11 christos you can't find via getitem. */ 244 1.11 christos for (struct symbol *sym : block_iterator_range (block, &lookup_name)) 245 1.9 christos { 246 1.9 christos /* Just stop at the first match */ 247 1.11 christos return symbol_to_symbol_object (sym); 248 1.9 christos } 249 1.9 christos 250 1.11 christos PyErr_SetObject (PyExc_KeyError, key); 251 1.11 christos return nullptr; 252 1.9 christos } 253 1.9 christos 254 1.12 christos /* Deleter function for the hash table. */ 255 1.12 christos 256 1.1 christos static void 257 1.12 christos block_object_del (void *obj) 258 1.1 christos { 259 1.1 christos block_object *block = (block_object *) obj; 260 1.12 christos block->block = nullptr; 261 1.12 christos block->objfile = nullptr; 262 1.12 christos } 263 1.12 christos 264 1.12 christos /* Hash function for the hash table. */ 265 1.12 christos 266 1.12 christos static hashval_t 267 1.12 christos block_object_hash (const void *obj) 268 1.12 christos { 269 1.12 christos const block_object *block = (const block_object *) obj; 270 1.12 christos return htab_hash_pointer (block->block); 271 1.12 christos } 272 1.1 christos 273 1.12 christos /* Equality function for the hash table. Note that searches must be 274 1.12 christos done with a plain block. */ 275 1.12 christos 276 1.12 christos static int 277 1.12 christos block_object_eq (const void *a, const void *b) 278 1.12 christos { 279 1.12 christos const block_object *blocka = (const block_object *) a; 280 1.12 christos const block *blockb = (const block *) b; 281 1.12 christos return blocka->block == blockb; 282 1.1 christos } 283 1.1 christos 284 1.12 christos /* Called when a gdb.Block is destroyed. This removes it from the 285 1.12 christos hash. */ 286 1.12 christos 287 1.1 christos static void 288 1.12 christos blpy_dealloc (PyObject *obj) 289 1.1 christos { 290 1.12 christos block_object *block = (block_object *) obj; 291 1.12 christos 292 1.12 christos if (block->objfile != nullptr) 293 1.1 christos { 294 1.12 christos htab_t table = blpy_objfile_data_key.get (block->objfile); 295 1.12 christos hashval_t hash = block_object_hash (block); 296 1.12 christos /* This will clear the contents of the block as a side 297 1.12 christos effect. */ 298 1.12 christos htab_remove_elt_with_hash (table, block->block, hash); 299 1.1 christos } 300 1.12 christos 301 1.12 christos Py_TYPE (obj)->tp_free (obj); 302 1.1 christos } 303 1.1 christos 304 1.1 christos /* Create a new block object (gdb.Block) that encapsulates the struct 305 1.1 christos block object from GDB. */ 306 1.1 christos PyObject * 307 1.1 christos block_to_block_object (const struct block *block, struct objfile *objfile) 308 1.1 christos { 309 1.12 christos htab_t table = blpy_objfile_data_key.get (objfile); 310 1.12 christos if (table == nullptr) 311 1.12 christos { 312 1.12 christos table = htab_create_alloc (10, block_object_hash, block_object_eq, 313 1.12 christos block_object_del, xcalloc, xfree); 314 1.12 christos blpy_objfile_data_key.set (objfile, table); 315 1.12 christos } 316 1.12 christos 317 1.12 christos hashval_t hash = htab_hash_pointer (block); 318 1.12 christos block_object *result = (block_object *) htab_find_with_hash (table, block, 319 1.12 christos hash); 320 1.12 christos if (result != nullptr) 321 1.12 christos { 322 1.12 christos PyObject *py_result = (PyObject *) result; 323 1.12 christos Py_INCREF (py_result); 324 1.12 christos return py_result; 325 1.12 christos } 326 1.12 christos 327 1.12 christos result = PyObject_New (block_object, &block_object_type); 328 1.12 christos result->block = block; 329 1.12 christos result->objfile = objfile; 330 1.1 christos 331 1.12 christos void **slot = htab_find_slot_with_hash (table, block, hash, INSERT); 332 1.12 christos *slot = result; 333 1.1 christos 334 1.12 christos return (PyObject *) result; 335 1.1 christos } 336 1.1 christos 337 1.1 christos /* Return struct block reference that is wrapped by this object. */ 338 1.1 christos const struct block * 339 1.1 christos block_object_to_block (PyObject *obj) 340 1.1 christos { 341 1.1 christos if (! PyObject_TypeCheck (obj, &block_object_type)) 342 1.1 christos return NULL; 343 1.1 christos return ((block_object *) obj)->block; 344 1.1 christos } 345 1.1 christos 346 1.1 christos /* Return a reference to the block iterator. */ 347 1.1 christos static PyObject * 348 1.1 christos blpy_block_syms_iter (PyObject *self) 349 1.1 christos { 350 1.1 christos block_syms_iterator_object *iter_obj = (block_syms_iterator_object *) self; 351 1.1 christos 352 1.1 christos BLPY_ITER_REQUIRE_VALID (iter_obj->source); 353 1.1 christos 354 1.1 christos Py_INCREF (self); 355 1.1 christos return self; 356 1.1 christos } 357 1.1 christos 358 1.1 christos /* Return the next symbol in the iteration through the block's 359 1.1 christos dictionary. */ 360 1.1 christos static PyObject * 361 1.1 christos blpy_block_syms_iternext (PyObject *self) 362 1.1 christos { 363 1.1 christos block_syms_iterator_object *iter_obj = (block_syms_iterator_object *) self; 364 1.1 christos struct symbol *sym; 365 1.1 christos 366 1.1 christos BLPY_ITER_REQUIRE_VALID (iter_obj->source); 367 1.1 christos 368 1.1 christos if (!iter_obj->initialized_p) 369 1.1 christos { 370 1.1 christos sym = block_iterator_first (iter_obj->block, &(iter_obj->iter)); 371 1.1 christos iter_obj->initialized_p = 1; 372 1.1 christos } 373 1.1 christos else 374 1.1 christos sym = block_iterator_next (&(iter_obj->iter)); 375 1.1 christos 376 1.1 christos if (sym == NULL) 377 1.1 christos { 378 1.1 christos PyErr_SetString (PyExc_StopIteration, _("Symbol is null.")); 379 1.1 christos return NULL; 380 1.1 christos } 381 1.1 christos 382 1.1 christos return symbol_to_symbol_object (sym); 383 1.1 christos } 384 1.1 christos 385 1.1 christos static void 386 1.1 christos blpy_block_syms_dealloc (PyObject *obj) 387 1.1 christos { 388 1.1 christos block_syms_iterator_object *iter_obj = (block_syms_iterator_object *) obj; 389 1.1 christos 390 1.1 christos Py_XDECREF (iter_obj->source); 391 1.9 christos Py_TYPE (obj)->tp_free (obj); 392 1.1 christos } 393 1.1 christos 394 1.1 christos /* Implementation of gdb.Block.is_valid (self) -> Boolean. 395 1.1 christos Returns True if this block object still exists in GDB. */ 396 1.1 christos 397 1.1 christos static PyObject * 398 1.1 christos blpy_is_valid (PyObject *self, PyObject *args) 399 1.1 christos { 400 1.1 christos const struct block *block; 401 1.1 christos 402 1.1 christos block = block_object_to_block (self); 403 1.1 christos if (block == NULL) 404 1.1 christos Py_RETURN_FALSE; 405 1.1 christos 406 1.1 christos Py_RETURN_TRUE; 407 1.1 christos } 408 1.1 christos 409 1.1 christos /* Implementation of gdb.BlockIterator.is_valid (self) -> Boolean. 410 1.1 christos Returns True if this block iterator object still exists in GDB */ 411 1.1 christos 412 1.1 christos static PyObject * 413 1.1 christos blpy_iter_is_valid (PyObject *self, PyObject *args) 414 1.1 christos { 415 1.1 christos block_syms_iterator_object *iter_obj = 416 1.1 christos (block_syms_iterator_object *) self; 417 1.1 christos 418 1.1 christos if (iter_obj->source->block == NULL) 419 1.1 christos Py_RETURN_FALSE; 420 1.1 christos 421 1.1 christos Py_RETURN_TRUE; 422 1.1 christos } 423 1.1 christos 424 1.11 christos /* __repr__ implementation for gdb.Block. */ 425 1.11 christos 426 1.11 christos static PyObject * 427 1.11 christos blpy_repr (PyObject *self) 428 1.11 christos { 429 1.11 christos const auto block = block_object_to_block (self); 430 1.11 christos if (block == nullptr) 431 1.11 christos return gdb_py_invalid_object_repr (self); 432 1.11 christos 433 1.11 christos const auto name = block->function () ? 434 1.11 christos block->function ()->print_name () : "<anonymous>"; 435 1.11 christos 436 1.11 christos std::string str; 437 1.11 christos unsigned int written_symbols = 0; 438 1.11 christos const int len = mdict_size (block->multidict ()); 439 1.11 christos static constexpr int SYMBOLS_TO_SHOW = 5; 440 1.11 christos for (struct symbol *symbol : block_iterator_range (block)) 441 1.11 christos { 442 1.11 christos if (written_symbols == SYMBOLS_TO_SHOW) 443 1.11 christos { 444 1.11 christos const int remaining = len - SYMBOLS_TO_SHOW; 445 1.11 christos if (remaining == 1) 446 1.11 christos str += string_printf ("... (%d more symbol)", remaining); 447 1.11 christos else 448 1.11 christos str += string_printf ("... (%d more symbols)", remaining); 449 1.11 christos break; 450 1.11 christos } 451 1.11 christos str += symbol->print_name (); 452 1.11 christos if (++written_symbols < len) 453 1.11 christos str += ", "; 454 1.11 christos } 455 1.11 christos return PyUnicode_FromFormat ("<%s %s {%s}>", Py_TYPE (self)->tp_name, 456 1.11 christos name, str.c_str ()); 457 1.11 christos } 458 1.11 christos 459 1.12 christos /* Hash function for block objects. */ 460 1.12 christos 461 1.12 christos static Py_hash_t 462 1.12 christos blpy_hash (PyObject *self) 463 1.12 christos { 464 1.12 christos /* Python doesn't really expose its pointer hash function, so we use 465 1.12 christos our own. */ 466 1.12 christos Py_hash_t result = (Py_hash_t) htab_hash_pointer (self); 467 1.12 christos /* -1 has a special meaning for Python. */ 468 1.12 christos if (result == -1) 469 1.12 christos result = -2; 470 1.12 christos return result; 471 1.12 christos } 472 1.12 christos 473 1.11 christos /* Implements the equality comparison for Block objects. All other 474 1.11 christos comparison operators will throw NotImplemented, as they aren't 475 1.11 christos valid for blocks. */ 476 1.11 christos 477 1.11 christos static PyObject * 478 1.11 christos blpy_richcompare (PyObject *self, PyObject *other, int op) 479 1.11 christos { 480 1.11 christos if (!PyObject_TypeCheck (other, &block_object_type) 481 1.11 christos || (op != Py_EQ && op != Py_NE)) 482 1.11 christos { 483 1.11 christos Py_INCREF (Py_NotImplemented); 484 1.11 christos return Py_NotImplemented; 485 1.11 christos } 486 1.11 christos 487 1.12 christos bool expected = self == other; 488 1.11 christos bool equal = op == Py_EQ; 489 1.11 christos return PyBool_FromLong (equal == expected); 490 1.11 christos } 491 1.11 christos 492 1.11 christos static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION 493 1.1 christos gdbpy_initialize_blocks (void) 494 1.1 christos { 495 1.1 christos block_object_type.tp_new = PyType_GenericNew; 496 1.12 christos if (gdbpy_type_ready (&block_object_type) < 0) 497 1.1 christos return -1; 498 1.1 christos 499 1.1 christos block_syms_iterator_object_type.tp_new = PyType_GenericNew; 500 1.12 christos if (gdbpy_type_ready (&block_syms_iterator_object_type) < 0) 501 1.1 christos return -1; 502 1.1 christos 503 1.12 christos return 0; 504 1.1 christos } 505 1.1 christos 506 1.11 christos GDBPY_INITIALIZE_FILE (gdbpy_initialize_blocks); 507 1.11 christos 508 1.1 christos 509 1.1 christos 511 1.1 christos static PyMethodDef block_object_methods[] = { 512 1.1 christos { "is_valid", blpy_is_valid, METH_NOARGS, 513 1.1 christos "is_valid () -> Boolean.\n\ 514 1.1 christos Return true if this block is valid, false if not." }, 515 1.1 christos {NULL} /* Sentinel */ 516 1.1 christos }; 517 1.7 christos 518 1.1 christos static gdb_PyGetSetDef block_object_getset[] = { 519 1.1 christos { "start", blpy_get_start, NULL, "Start address of the block.", NULL }, 520 1.1 christos { "end", blpy_get_end, NULL, "End address of the block.", NULL }, 521 1.1 christos { "function", blpy_get_function, NULL, 522 1.1 christos "Symbol that names the block, or None.", NULL }, 523 1.1 christos { "superblock", blpy_get_superblock, NULL, 524 1.1 christos "Block containing the block, or None.", NULL }, 525 1.1 christos { "global_block", blpy_get_global_block, NULL, 526 1.1 christos "Block containing the global block.", NULL }, 527 1.1 christos { "static_block", blpy_get_static_block, NULL, 528 1.1 christos "Block containing the static block.", NULL }, 529 1.1 christos { "is_static", blpy_is_static, NULL, 530 1.1 christos "Whether this block is a static block.", NULL }, 531 1.1 christos { "is_global", blpy_is_global, NULL, 532 1.1 christos "Whether this block is a global block.", NULL }, 533 1.1 christos { NULL } /* Sentinel */ 534 1.1 christos }; 535 1.9 christos 536 1.9 christos static PyMappingMethods block_object_as_mapping = { 537 1.9 christos NULL, 538 1.9 christos blpy_getitem, 539 1.9 christos NULL 540 1.9 christos }; 541 1.1 christos 542 1.1 christos PyTypeObject block_object_type = { 543 1.1 christos PyVarObject_HEAD_INIT (NULL, 0) 544 1.1 christos "gdb.Block", /*tp_name*/ 545 1.1 christos sizeof (block_object), /*tp_basicsize*/ 546 1.1 christos 0, /*tp_itemsize*/ 547 1.1 christos blpy_dealloc, /*tp_dealloc*/ 548 1.1 christos 0, /*tp_print*/ 549 1.1 christos 0, /*tp_getattr*/ 550 1.1 christos 0, /*tp_setattr*/ 551 1.11 christos 0, /*tp_compare*/ 552 1.1 christos blpy_repr, /*tp_repr*/ 553 1.1 christos 0, /*tp_as_number*/ 554 1.9 christos 0, /*tp_as_sequence*/ 555 1.12 christos &block_object_as_mapping, /*tp_as_mapping*/ 556 1.1 christos blpy_hash, /*tp_hash */ 557 1.1 christos 0, /*tp_call*/ 558 1.1 christos 0, /*tp_str*/ 559 1.1 christos 0, /*tp_getattro*/ 560 1.1 christos 0, /*tp_setattro*/ 561 1.10 christos 0, /*tp_as_buffer*/ 562 1.1 christos Py_TPFLAGS_DEFAULT, /*tp_flags*/ 563 1.1 christos "GDB block object", /* tp_doc */ 564 1.1 christos 0, /* tp_traverse */ 565 1.11 christos 0, /* tp_clear */ 566 1.1 christos blpy_richcompare, /* tp_richcompare */ 567 1.1 christos 0, /* tp_weaklistoffset */ 568 1.1 christos blpy_iter, /* tp_iter */ 569 1.1 christos 0, /* tp_iternext */ 570 1.1 christos block_object_methods, /* tp_methods */ 571 1.1 christos 0, /* tp_members */ 572 1.1 christos block_object_getset /* tp_getset */ 573 1.1 christos }; 574 1.1 christos 575 1.1 christos static PyMethodDef block_iterator_object_methods[] = { 576 1.1 christos { "is_valid", blpy_iter_is_valid, METH_NOARGS, 577 1.1 christos "is_valid () -> Boolean.\n\ 578 1.1 christos Return true if this block iterator is valid, false if not." }, 579 1.1 christos {NULL} /* Sentinel */ 580 1.1 christos }; 581 1.5 christos 582 1.1 christos PyTypeObject block_syms_iterator_object_type = { 583 1.1 christos PyVarObject_HEAD_INIT (NULL, 0) 584 1.1 christos "gdb.BlockIterator", /*tp_name*/ 585 1.1 christos sizeof (block_syms_iterator_object), /*tp_basicsize*/ 586 1.1 christos 0, /*tp_itemsize*/ 587 1.1 christos blpy_block_syms_dealloc, /*tp_dealloc*/ 588 1.1 christos 0, /*tp_print*/ 589 1.1 christos 0, /*tp_getattr*/ 590 1.1 christos 0, /*tp_setattr*/ 591 1.1 christos 0, /*tp_compare*/ 592 1.1 christos 0, /*tp_repr*/ 593 1.1 christos 0, /*tp_as_number*/ 594 1.1 christos 0, /*tp_as_sequence*/ 595 1.1 christos 0, /*tp_as_mapping*/ 596 1.1 christos 0, /*tp_hash */ 597 1.1 christos 0, /*tp_call*/ 598 1.1 christos 0, /*tp_str*/ 599 1.1 christos 0, /*tp_getattro*/ 600 1.1 christos 0, /*tp_setattro*/ 601 1.10 christos 0, /*tp_as_buffer*/ 602 1.1 christos Py_TPFLAGS_DEFAULT, /*tp_flags*/ 603 1.1 christos "GDB block syms iterator object", /*tp_doc */ 604 1.1 christos 0, /*tp_traverse */ 605 1.1 christos 0, /*tp_clear */ 606 1.1 christos 0, /*tp_richcompare */ 607 1.1 christos 0, /*tp_weaklistoffset */ 608 1.1 christos blpy_block_syms_iter, /*tp_iter */ 609 1.1 christos blpy_block_syms_iternext, /*tp_iternext */ 610 1.1 christos block_iterator_object_methods /*tp_methods */ 611 }; 612