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