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