]>
Commit | Line | Data |
---|---|---|
f3e9a817 PM |
1 | /* Python interface to symbol tables. |
2 | ||
42a4f53d | 3 | Copyright (C) 2008-2019 Free Software Foundation, Inc. |
f3e9a817 PM |
4 | |
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 3 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
19 | ||
20 | #include "defs.h" | |
21 | #include "charset.h" | |
22 | #include "symtab.h" | |
23 | #include "source.h" | |
24 | #include "python-internal.h" | |
25 | #include "objfiles.h" | |
a20ee7a4 | 26 | #include "block.h" |
88b6faea | 27 | #include "py-ref.h" |
f3e9a817 PM |
28 | |
29 | typedef struct stpy_symtab_object { | |
30 | PyObject_HEAD | |
31 | /* The GDB Symbol table structure. */ | |
32 | struct symtab *symtab; | |
33 | /* A symtab object is associated with an objfile, so keep track with | |
34 | a doubly-linked list, rooted in the objfile. This allows | |
35 | invalidation of the underlying struct symtab when the objfile is | |
36 | deleted. */ | |
37 | struct stpy_symtab_object *prev; | |
38 | struct stpy_symtab_object *next; | |
39 | } symtab_object; | |
40 | ||
e36122e9 | 41 | extern PyTypeObject symtab_object_type |
62eec1a5 | 42 | CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("symtab_object"); |
f3e9a817 PM |
43 | static const struct objfile_data *stpy_objfile_data_key; |
44 | ||
45 | /* Require a valid symbol table. All access to symtab_object->symtab | |
46 | should be gated by this call. */ | |
47 | #define STPY_REQUIRE_VALID(symtab_obj, symtab) \ | |
48 | do { \ | |
49 | symtab = symtab_object_to_symtab (symtab_obj); \ | |
50 | if (symtab == NULL) \ | |
51 | { \ | |
52 | PyErr_SetString (PyExc_RuntimeError, \ | |
53 | _("Symbol Table is invalid.")); \ | |
54 | return NULL; \ | |
55 | } \ | |
56 | } while (0) | |
57 | ||
58 | typedef struct salpy_sal_object { | |
59 | PyObject_HEAD | |
60 | /* The GDB Symbol table structure. */ | |
61 | symtab_object *symtab; | |
62 | /* The GDB Symbol table and line structure. */ | |
63 | struct symtab_and_line *sal; | |
64 | /* A Symtab and line object is associated with an objfile, so keep | |
65 | track with a doubly-linked list, rooted in the objfile. This | |
66 | allows invalidation of the underlying struct symtab_and_line | |
67 | when the objfile is deleted. */ | |
68 | struct salpy_sal_object *prev; | |
69 | struct salpy_sal_object *next; | |
70 | } sal_object; | |
71 | ||
e36122e9 | 72 | extern PyTypeObject sal_object_type |
62eec1a5 | 73 | CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("sal_object"); |
f3e9a817 PM |
74 | static const struct objfile_data *salpy_objfile_data_key; |
75 | ||
76 | /* Require a valid symbol table and line object. All access to | |
77 | sal_object->sal should be gated by this call. */ | |
78 | #define SALPY_REQUIRE_VALID(sal_obj, sal) \ | |
79 | do { \ | |
80 | sal = sal_object_to_symtab_and_line (sal_obj); \ | |
81 | if (sal == NULL) \ | |
82 | { \ | |
83 | PyErr_SetString (PyExc_RuntimeError, \ | |
84 | _("Symbol Table and Line is invalid.")); \ | |
85 | return NULL; \ | |
86 | } \ | |
87 | } while (0) | |
88 | ||
89 | static PyObject * | |
90 | stpy_str (PyObject *self) | |
91 | { | |
92 | PyObject *result; | |
93 | struct symtab *symtab = NULL; | |
94 | ||
95 | STPY_REQUIRE_VALID (self, symtab); | |
96 | ||
05cba821 | 97 | result = PyString_FromString (symtab_to_filename_for_display (symtab)); |
f3e9a817 PM |
98 | |
99 | return result; | |
100 | } | |
101 | ||
102 | static PyObject * | |
103 | stpy_get_filename (PyObject *self, void *closure) | |
104 | { | |
105 | PyObject *str_obj; | |
106 | struct symtab *symtab = NULL; | |
05cba821 | 107 | const char *filename; |
f3e9a817 PM |
108 | |
109 | STPY_REQUIRE_VALID (self, symtab); | |
05cba821 | 110 | filename = symtab_to_filename_for_display (symtab); |
f3e9a817 | 111 | |
833d985d | 112 | str_obj = host_string_to_python_string (filename).release (); |
f3e9a817 PM |
113 | return str_obj; |
114 | } | |
115 | ||
116 | static PyObject * | |
117 | stpy_get_objfile (PyObject *self, void *closure) | |
118 | { | |
119 | struct symtab *symtab = NULL; | |
f3e9a817 PM |
120 | |
121 | STPY_REQUIRE_VALID (self, symtab); | |
122 | ||
0a9db5ad | 123 | return objfile_to_objfile_object (SYMTAB_OBJFILE (symtab)).release (); |
f3e9a817 PM |
124 | } |
125 | ||
2b4fd423 DE |
126 | /* Getter function for symtab.producer. */ |
127 | ||
128 | static PyObject * | |
129 | stpy_get_producer (PyObject *self, void *closure) | |
130 | { | |
131 | struct symtab *symtab = NULL; | |
43f3e411 | 132 | struct compunit_symtab *cust; |
2b4fd423 DE |
133 | |
134 | STPY_REQUIRE_VALID (self, symtab); | |
43f3e411 DE |
135 | cust = SYMTAB_COMPUNIT (symtab); |
136 | if (COMPUNIT_PRODUCER (cust) != NULL) | |
2b4fd423 | 137 | { |
43f3e411 | 138 | const char *producer = COMPUNIT_PRODUCER (cust); |
2b4fd423 | 139 | |
833d985d | 140 | return host_string_to_python_string (producer).release (); |
2b4fd423 DE |
141 | } |
142 | ||
143 | Py_RETURN_NONE; | |
144 | } | |
145 | ||
f3e9a817 PM |
146 | static PyObject * |
147 | stpy_fullname (PyObject *self, PyObject *args) | |
148 | { | |
0b0865da | 149 | const char *fullname; |
f3e9a817 PM |
150 | struct symtab *symtab = NULL; |
151 | ||
152 | STPY_REQUIRE_VALID (self, symtab); | |
153 | ||
154 | fullname = symtab_to_fullname (symtab); | |
f3e9a817 | 155 | |
833d985d | 156 | return host_string_to_python_string (fullname).release (); |
f3e9a817 PM |
157 | } |
158 | ||
29703da4 PM |
159 | /* Implementation of gdb.Symtab.is_valid (self) -> Boolean. |
160 | Returns True if this Symbol table still exists in GDB. */ | |
161 | ||
162 | static PyObject * | |
163 | stpy_is_valid (PyObject *self, PyObject *args) | |
164 | { | |
165 | struct symtab *symtab = NULL; | |
166 | ||
167 | symtab = symtab_object_to_symtab (self); | |
168 | if (symtab == NULL) | |
169 | Py_RETURN_FALSE; | |
170 | ||
171 | Py_RETURN_TRUE; | |
172 | } | |
173 | ||
a20ee7a4 SCR |
174 | /* Return the GLOBAL_BLOCK of the underlying symtab. */ |
175 | ||
176 | static PyObject * | |
177 | stpy_global_block (PyObject *self, PyObject *args) | |
178 | { | |
179 | struct symtab *symtab = NULL; | |
180 | struct block *block = NULL; | |
346d1dfe | 181 | const struct blockvector *blockvector; |
a20ee7a4 SCR |
182 | |
183 | STPY_REQUIRE_VALID (self, symtab); | |
184 | ||
439247b6 | 185 | blockvector = SYMTAB_BLOCKVECTOR (symtab); |
a20ee7a4 | 186 | block = BLOCKVECTOR_BLOCK (blockvector, GLOBAL_BLOCK); |
eb822aa6 | 187 | return block_to_block_object (block, SYMTAB_OBJFILE (symtab)); |
a20ee7a4 SCR |
188 | } |
189 | ||
190 | /* Return the STATIC_BLOCK of the underlying symtab. */ | |
191 | ||
192 | static PyObject * | |
193 | stpy_static_block (PyObject *self, PyObject *args) | |
194 | { | |
195 | struct symtab *symtab = NULL; | |
196 | struct block *block = NULL; | |
346d1dfe | 197 | const struct blockvector *blockvector; |
a20ee7a4 SCR |
198 | |
199 | STPY_REQUIRE_VALID (self, symtab); | |
200 | ||
439247b6 | 201 | blockvector = SYMTAB_BLOCKVECTOR (symtab); |
a20ee7a4 | 202 | block = BLOCKVECTOR_BLOCK (blockvector, STATIC_BLOCK); |
eb822aa6 | 203 | return block_to_block_object (block, SYMTAB_OBJFILE (symtab)); |
a20ee7a4 SCR |
204 | } |
205 | ||
4efd80aa CS |
206 | /* Implementation of gdb.Symtab.linetable (self) -> gdb.LineTable. |
207 | Returns a gdb.LineTable object corresponding to this symbol | |
bc79de95 PM |
208 | table. */ |
209 | ||
210 | static PyObject * | |
211 | stpy_get_linetable (PyObject *self, PyObject *args) | |
212 | { | |
213 | struct symtab *symtab = NULL; | |
214 | ||
215 | STPY_REQUIRE_VALID (self, symtab); | |
216 | ||
217 | return symtab_to_linetable_object (self); | |
218 | } | |
219 | ||
f3e9a817 PM |
220 | static PyObject * |
221 | salpy_str (PyObject *self) | |
222 | { | |
05cba821 | 223 | const char *filename; |
f3e9a817 | 224 | sal_object *sal_obj; |
f3e9a817 PM |
225 | struct symtab_and_line *sal = NULL; |
226 | ||
227 | SALPY_REQUIRE_VALID (self, sal); | |
228 | ||
229 | sal_obj = (sal_object *) self; | |
230 | filename = (sal_obj->symtab == (symtab_object *) Py_None) | |
05cba821 | 231 | ? "<unknown>" : symtab_to_filename_for_display (sal_obj->symtab->symtab); |
f3e9a817 | 232 | |
075c55e0 TT |
233 | return PyString_FromFormat ("symbol and line for %s, line %d", filename, |
234 | sal->line); | |
f3e9a817 PM |
235 | } |
236 | ||
237 | static void | |
238 | stpy_dealloc (PyObject *obj) | |
239 | { | |
240 | symtab_object *symtab = (symtab_object *) obj; | |
241 | ||
242 | if (symtab->prev) | |
243 | symtab->prev->next = symtab->next; | |
244 | else if (symtab->symtab) | |
245 | { | |
eb822aa6 | 246 | set_objfile_data (SYMTAB_OBJFILE (symtab->symtab), |
f3e9a817 PM |
247 | stpy_objfile_data_key, symtab->next); |
248 | } | |
249 | if (symtab->next) | |
250 | symtab->next->prev = symtab->prev; | |
251 | symtab->symtab = NULL; | |
252 | } | |
253 | ||
254 | ||
255 | static PyObject * | |
256 | salpy_get_pc (PyObject *self, void *closure) | |
257 | { | |
258 | struct symtab_and_line *sal = NULL; | |
259 | ||
260 | SALPY_REQUIRE_VALID (self, sal); | |
261 | ||
74aedc46 | 262 | return gdb_py_long_from_ulongest (sal->pc); |
f3e9a817 PM |
263 | } |
264 | ||
ee0bf529 SCR |
265 | /* Implementation of the get method for the 'last' attribute of |
266 | gdb.Symtab_and_line. */ | |
267 | ||
268 | static PyObject * | |
269 | salpy_get_last (PyObject *self, void *closure) | |
270 | { | |
271 | struct symtab_and_line *sal = NULL; | |
272 | ||
273 | SALPY_REQUIRE_VALID (self, sal); | |
274 | ||
275 | if (sal->end > 0) | |
276 | return gdb_py_long_from_ulongest (sal->end - 1); | |
277 | else | |
278 | Py_RETURN_NONE; | |
279 | } | |
280 | ||
f3e9a817 PM |
281 | static PyObject * |
282 | salpy_get_line (PyObject *self, void *closure) | |
283 | { | |
284 | struct symtab_and_line *sal = NULL; | |
285 | ||
286 | SALPY_REQUIRE_VALID (self, sal); | |
287 | ||
74aedc46 | 288 | return PyInt_FromLong (sal->line); |
f3e9a817 PM |
289 | } |
290 | ||
291 | static PyObject * | |
292 | salpy_get_symtab (PyObject *self, void *closure) | |
293 | { | |
294 | struct symtab_and_line *sal; | |
295 | sal_object *self_sal = (sal_object *) self; | |
296 | ||
297 | SALPY_REQUIRE_VALID (self, sal); | |
298 | ||
299 | Py_INCREF (self_sal->symtab); | |
300 | ||
301 | return (PyObject *) self_sal->symtab; | |
302 | } | |
303 | ||
29703da4 PM |
304 | /* Implementation of gdb.Symtab_and_line.is_valid (self) -> Boolean. |
305 | Returns True if this Symbol table and line object still exists GDB. */ | |
306 | ||
307 | static PyObject * | |
308 | salpy_is_valid (PyObject *self, PyObject *args) | |
309 | { | |
310 | struct symtab_and_line *sal; | |
311 | ||
312 | sal = sal_object_to_symtab_and_line (self); | |
313 | if (sal == NULL) | |
314 | Py_RETURN_FALSE; | |
315 | ||
316 | Py_RETURN_TRUE; | |
317 | } | |
318 | ||
f3e9a817 PM |
319 | static void |
320 | salpy_dealloc (PyObject *self) | |
321 | { | |
322 | sal_object *self_sal = (sal_object *) self; | |
323 | ||
324 | if (self_sal->prev) | |
325 | self_sal->prev->next = self_sal->next; | |
326 | else if (self_sal->symtab != (symtab_object * ) Py_None) | |
eb822aa6 | 327 | set_objfile_data (SYMTAB_OBJFILE (self_sal->symtab->symtab), |
f3e9a817 PM |
328 | salpy_objfile_data_key, self_sal->next); |
329 | ||
330 | if (self_sal->next) | |
331 | self_sal->next->prev = self_sal->prev; | |
332 | ||
333 | Py_DECREF (self_sal->symtab); | |
334 | xfree (self_sal->sal); | |
9a27f2c6 | 335 | Py_TYPE (self)->tp_free (self); |
f3e9a817 PM |
336 | } |
337 | ||
b021a221 MS |
338 | /* Given a sal, and a sal_object that has previously been allocated |
339 | and initialized, populate the sal_object with the struct sal data. | |
340 | Also, register the sal_object life-cycle with the life-cycle of the | |
341 | object file associated with this sal, if needed. If a failure | |
33ee792f TT |
342 | occurs during the sal population, this function will return -1. */ |
343 | static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION | |
f3e9a817 PM |
344 | set_sal (sal_object *sal_obj, struct symtab_and_line sal) |
345 | { | |
346 | symtab_object *symtab_obj; | |
347 | ||
348 | if (sal.symtab) | |
349 | { | |
350 | symtab_obj = (symtab_object *) symtab_to_symtab_object (sal.symtab); | |
351 | /* If a symtab existed in the sal, but it cannot be duplicated, | |
352 | we exit. */ | |
353 | if (symtab_obj == NULL) | |
33ee792f | 354 | return -1; |
f3e9a817 PM |
355 | } |
356 | else | |
357 | { | |
358 | symtab_obj = (symtab_object *) Py_None; | |
359 | Py_INCREF (Py_None); | |
360 | } | |
361 | ||
224c3ddb SM |
362 | sal_obj->sal = ((struct symtab_and_line *) |
363 | xmemdup (&sal, sizeof (struct symtab_and_line), | |
364 | sizeof (struct symtab_and_line))); | |
f3e9a817 PM |
365 | sal_obj->symtab = symtab_obj; |
366 | sal_obj->prev = NULL; | |
367 | ||
368 | /* If the SAL does not have a symtab, we do not add it to the | |
369 | objfile cleanup observer linked list. */ | |
370 | if (sal_obj->symtab != (symtab_object *)Py_None) | |
371 | { | |
19ba03f4 SM |
372 | sal_obj->next |
373 | = ((struct salpy_sal_object *) | |
374 | objfile_data (SYMTAB_OBJFILE (sal_obj->symtab->symtab), | |
375 | salpy_objfile_data_key)); | |
f3e9a817 PM |
376 | if (sal_obj->next) |
377 | sal_obj->next->prev = sal_obj; | |
378 | ||
eb822aa6 | 379 | set_objfile_data (SYMTAB_OBJFILE (sal_obj->symtab->symtab), |
f3e9a817 PM |
380 | salpy_objfile_data_key, sal_obj); |
381 | } | |
382 | else | |
383 | sal_obj->next = NULL; | |
384 | ||
33ee792f | 385 | return 0; |
f3e9a817 PM |
386 | } |
387 | ||
388 | /* Given a symtab, and a symtab_object that has previously been | |
389 | allocated and initialized, populate the symtab_object with the | |
390 | struct symtab data. Also, register the symtab_object life-cycle | |
b021a221 | 391 | with the life-cycle of the object file associated with this |
f3e9a817 PM |
392 | symtab, if needed. */ |
393 | static void | |
394 | set_symtab (symtab_object *obj, struct symtab *symtab) | |
395 | { | |
396 | obj->symtab = symtab; | |
397 | obj->prev = NULL; | |
398 | if (symtab) | |
399 | { | |
19ba03f4 SM |
400 | obj->next |
401 | = ((struct stpy_symtab_object *) | |
402 | objfile_data (SYMTAB_OBJFILE (symtab), stpy_objfile_data_key)); | |
f3e9a817 PM |
403 | if (obj->next) |
404 | obj->next->prev = obj; | |
eb822aa6 | 405 | set_objfile_data (SYMTAB_OBJFILE (symtab), stpy_objfile_data_key, obj); |
f3e9a817 PM |
406 | } |
407 | else | |
408 | obj->next = NULL; | |
409 | } | |
410 | ||
411 | /* Create a new symbol table (gdb.Symtab) object that encapsulates the | |
412 | symtab structure from GDB. */ | |
413 | PyObject * | |
414 | symtab_to_symtab_object (struct symtab *symtab) | |
415 | { | |
416 | symtab_object *symtab_obj; | |
417 | ||
418 | symtab_obj = PyObject_New (symtab_object, &symtab_object_type); | |
419 | if (symtab_obj) | |
420 | set_symtab (symtab_obj, symtab); | |
421 | ||
422 | return (PyObject *) symtab_obj; | |
423 | } | |
424 | ||
425 | /* Create a new symtab and line (gdb.Symtab_and_line) object | |
426 | that encapsulates the symtab_and_line structure from GDB. */ | |
427 | PyObject * | |
428 | symtab_and_line_to_sal_object (struct symtab_and_line sal) | |
f3e9a817 | 429 | { |
88b6faea TT |
430 | gdbpy_ref<sal_object> sal_obj (PyObject_New (sal_object, &sal_object_type)); |
431 | if (sal_obj != NULL) | |
f3e9a817 | 432 | { |
88b6faea TT |
433 | if (set_sal (sal_obj.get (), sal) < 0) |
434 | return NULL; | |
f3e9a817 PM |
435 | } |
436 | ||
88b6faea | 437 | return (PyObject *) sal_obj.release (); |
f3e9a817 PM |
438 | } |
439 | ||
440 | /* Return struct symtab_and_line reference that is wrapped by this | |
441 | object. */ | |
442 | struct symtab_and_line * | |
443 | sal_object_to_symtab_and_line (PyObject *obj) | |
444 | { | |
445 | if (! PyObject_TypeCheck (obj, &sal_object_type)) | |
446 | return NULL; | |
447 | return ((sal_object *) obj)->sal; | |
448 | } | |
449 | ||
450 | /* Return struct symtab reference that is wrapped by this object. */ | |
451 | struct symtab * | |
452 | symtab_object_to_symtab (PyObject *obj) | |
453 | { | |
454 | if (! PyObject_TypeCheck (obj, &symtab_object_type)) | |
455 | return NULL; | |
456 | return ((symtab_object *) obj)->symtab; | |
457 | } | |
458 | ||
459 | /* This function is called when an objfile is about to be freed. | |
460 | Invalidate the symbol table as further actions on the symbol table | |
461 | would result in bad data. All access to obj->symtab should be | |
462 | gated by STPY_REQUIRE_VALID which will raise an exception on | |
463 | invalid symbol tables. */ | |
464 | static void | |
465 | del_objfile_symtab (struct objfile *objfile, void *datum) | |
466 | { | |
19ba03f4 | 467 | symtab_object *obj = (symtab_object *) datum; |
d59b6f6c | 468 | |
f3e9a817 PM |
469 | while (obj) |
470 | { | |
471 | symtab_object *next = obj->next; | |
472 | ||
473 | obj->symtab = NULL; | |
474 | obj->next = NULL; | |
475 | obj->prev = NULL; | |
476 | obj = next; | |
477 | } | |
478 | } | |
479 | ||
480 | /* This function is called when an objfile is about to be freed. | |
481 | Invalidate the sal object as further actions on the sal | |
482 | would result in bad data. All access to obj->sal should be | |
483 | gated by SALPY_REQUIRE_VALID which will raise an exception on | |
484 | invalid symbol table and line objects. */ | |
485 | static void | |
486 | del_objfile_sal (struct objfile *objfile, void *datum) | |
487 | { | |
19ba03f4 | 488 | sal_object *obj = (sal_object *) datum; |
d59b6f6c | 489 | |
f3e9a817 PM |
490 | while (obj) |
491 | { | |
492 | sal_object *next = obj->next; | |
493 | ||
801e4185 TT |
494 | Py_DECREF (obj->symtab); |
495 | obj->symtab = (symtab_object *) Py_None; | |
496 | Py_INCREF (Py_None); | |
497 | ||
f3e9a817 PM |
498 | obj->next = NULL; |
499 | obj->prev = NULL; | |
500 | xfree (obj->sal); | |
501 | obj->sal = NULL; | |
502 | ||
503 | obj = next; | |
504 | } | |
505 | } | |
506 | ||
999633ed | 507 | int |
f3e9a817 PM |
508 | gdbpy_initialize_symtabs (void) |
509 | { | |
510 | symtab_object_type.tp_new = PyType_GenericNew; | |
511 | if (PyType_Ready (&symtab_object_type) < 0) | |
999633ed | 512 | return -1; |
f3e9a817 PM |
513 | |
514 | sal_object_type.tp_new = PyType_GenericNew; | |
515 | if (PyType_Ready (&sal_object_type) < 0) | |
999633ed | 516 | return -1; |
f3e9a817 PM |
517 | |
518 | /* Register an objfile "free" callback so we can properly | |
519 | invalidate symbol tables, and symbol table and line data | |
520 | structures when an object file that is about to be | |
521 | deleted. */ | |
522 | stpy_objfile_data_key | |
523 | = register_objfile_data_with_cleanup (NULL, del_objfile_symtab); | |
524 | salpy_objfile_data_key | |
525 | = register_objfile_data_with_cleanup (NULL, del_objfile_sal); | |
526 | ||
aa36459a TT |
527 | if (gdb_pymodule_addobject (gdb_module, "Symtab", |
528 | (PyObject *) &symtab_object_type) < 0) | |
999633ed | 529 | return -1; |
f3e9a817 | 530 | |
aa36459a TT |
531 | return gdb_pymodule_addobject (gdb_module, "Symtab_and_line", |
532 | (PyObject *) &sal_object_type); | |
f3e9a817 PM |
533 | } |
534 | ||
535 | \f | |
536 | ||
0d1f4ceb | 537 | static gdb_PyGetSetDef symtab_object_getset[] = { |
f3e9a817 PM |
538 | { "filename", stpy_get_filename, NULL, |
539 | "The symbol table's source filename.", NULL }, | |
540 | { "objfile", stpy_get_objfile, NULL, "The symtab's objfile.", | |
541 | NULL }, | |
2b4fd423 DE |
542 | { "producer", stpy_get_producer, NULL, |
543 | "The name/version of the program that compiled this symtab.", NULL }, | |
f3e9a817 PM |
544 | {NULL} /* Sentinel */ |
545 | }; | |
546 | ||
547 | static PyMethodDef symtab_object_methods[] = { | |
29703da4 PM |
548 | { "is_valid", stpy_is_valid, METH_NOARGS, |
549 | "is_valid () -> Boolean.\n\ | |
550 | Return true if this symbol table is valid, false if not." }, | |
f3e9a817 PM |
551 | { "fullname", stpy_fullname, METH_NOARGS, |
552 | "fullname () -> String.\n\ | |
553 | Return the symtab's full source filename." }, | |
a20ee7a4 SCR |
554 | { "global_block", stpy_global_block, METH_NOARGS, |
555 | "global_block () -> gdb.Block.\n\ | |
556 | Return the global block of the symbol table." }, | |
557 | { "static_block", stpy_static_block, METH_NOARGS, | |
558 | "static_block () -> gdb.Block.\n\ | |
559 | Return the static block of the symbol table." }, | |
bc79de95 | 560 | { "linetable", stpy_get_linetable, METH_NOARGS, |
4efd80aa CS |
561 | "linetable () -> gdb.LineTable.\n\ |
562 | Return the LineTable associated with this symbol table" }, | |
f3e9a817 PM |
563 | {NULL} /* Sentinel */ |
564 | }; | |
565 | ||
e36122e9 | 566 | PyTypeObject symtab_object_type = { |
9a27f2c6 | 567 | PyVarObject_HEAD_INIT (NULL, 0) |
f3e9a817 PM |
568 | "gdb.Symtab", /*tp_name*/ |
569 | sizeof (symtab_object), /*tp_basicsize*/ | |
570 | 0, /*tp_itemsize*/ | |
571 | stpy_dealloc, /*tp_dealloc*/ | |
572 | 0, /*tp_print*/ | |
573 | 0, /*tp_getattr*/ | |
574 | 0, /*tp_setattr*/ | |
575 | 0, /*tp_compare*/ | |
576 | 0, /*tp_repr*/ | |
577 | 0, /*tp_as_number*/ | |
578 | 0, /*tp_as_sequence*/ | |
579 | 0, /*tp_as_mapping*/ | |
580 | 0, /*tp_hash */ | |
581 | 0, /*tp_call*/ | |
582 | stpy_str, /*tp_str*/ | |
583 | 0, /*tp_getattro*/ | |
584 | 0, /*tp_setattro*/ | |
585 | 0, /*tp_as_buffer*/ | |
586 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ | |
587 | "GDB symtab object", /*tp_doc */ | |
588 | 0, /*tp_traverse */ | |
589 | 0, /*tp_clear */ | |
590 | 0, /*tp_richcompare */ | |
591 | 0, /*tp_weaklistoffset */ | |
592 | 0, /*tp_iter */ | |
593 | 0, /*tp_iternext */ | |
594 | symtab_object_methods, /*tp_methods */ | |
595 | 0, /*tp_members */ | |
596 | symtab_object_getset /*tp_getset */ | |
597 | }; | |
598 | ||
0d1f4ceb | 599 | static gdb_PyGetSetDef sal_object_getset[] = { |
f3e9a817 PM |
600 | { "symtab", salpy_get_symtab, NULL, "Symtab object.", NULL }, |
601 | { "pc", salpy_get_pc, NULL, "Return the symtab_and_line's pc.", NULL }, | |
ee0bf529 SCR |
602 | { "last", salpy_get_last, NULL, |
603 | "Return the symtab_and_line's last address.", NULL }, | |
f3e9a817 PM |
604 | { "line", salpy_get_line, NULL, |
605 | "Return the symtab_and_line's line.", NULL }, | |
606 | {NULL} /* Sentinel */ | |
607 | }; | |
608 | ||
29703da4 PM |
609 | static PyMethodDef sal_object_methods[] = { |
610 | { "is_valid", salpy_is_valid, METH_NOARGS, | |
611 | "is_valid () -> Boolean.\n\ | |
612 | Return true if this symbol table and line is valid, false if not." }, | |
613 | {NULL} /* Sentinel */ | |
614 | }; | |
615 | ||
e36122e9 | 616 | PyTypeObject sal_object_type = { |
9a27f2c6 | 617 | PyVarObject_HEAD_INIT (NULL, 0) |
f3e9a817 PM |
618 | "gdb.Symtab_and_line", /*tp_name*/ |
619 | sizeof (sal_object), /*tp_basicsize*/ | |
620 | 0, /*tp_itemsize*/ | |
621 | salpy_dealloc, /*tp_dealloc*/ | |
622 | 0, /*tp_print*/ | |
623 | 0, /*tp_getattr*/ | |
624 | 0, /*tp_setattr*/ | |
625 | 0, /*tp_compare*/ | |
626 | 0, /*tp_repr*/ | |
627 | 0, /*tp_as_number*/ | |
628 | 0, /*tp_as_sequence*/ | |
629 | 0, /*tp_as_mapping*/ | |
630 | 0, /*tp_hash */ | |
631 | 0, /*tp_call*/ | |
632 | salpy_str, /*tp_str*/ | |
633 | 0, /*tp_getattro*/ | |
634 | 0, /*tp_setattro*/ | |
635 | 0, /*tp_as_buffer*/ | |
636 | Py_TPFLAGS_DEFAULT, /*tp_flags*/ | |
637 | "GDB symtab_and_line object", /*tp_doc */ | |
638 | 0, /*tp_traverse */ | |
639 | 0, /*tp_clear */ | |
640 | 0, /*tp_richcompare */ | |
641 | 0, /*tp_weaklistoffset */ | |
642 | 0, /*tp_iter */ | |
643 | 0, /*tp_iternext */ | |
29703da4 | 644 | sal_object_methods, /*tp_methods */ |
f3e9a817 PM |
645 | 0, /*tp_members */ |
646 | sal_object_getset /*tp_getset */ | |
647 | }; |