]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/python/py-symbol.c
Automatic Copyright Year update after running gdb/copyright.py
[thirdparty/binutils-gdb.git] / gdb / python / py-symbol.c
1 /* Python interface to symbols.
2
3 Copyright (C) 2008-2022 Free Software Foundation, Inc.
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 "block.h"
22 #include "frame.h"
23 #include "symtab.h"
24 #include "python-internal.h"
25 #include "objfiles.h"
26 #include "symfile.h"
27
28 struct symbol_object {
29 PyObject_HEAD
30 /* The GDB symbol structure this object is wrapping. */
31 struct symbol *symbol;
32 /* A symbol object is associated with an objfile, so keep track with
33 doubly-linked list, rooted in the objfile. This lets us
34 invalidate the underlying struct symbol when the objfile is
35 deleted. */
36 symbol_object *prev;
37 symbol_object *next;
38 };
39
40 /* Require a valid symbol. All access to symbol_object->symbol should be
41 gated by this call. */
42 #define SYMPY_REQUIRE_VALID(symbol_obj, symbol) \
43 do { \
44 symbol = symbol_object_to_symbol (symbol_obj); \
45 if (symbol == NULL) \
46 { \
47 PyErr_SetString (PyExc_RuntimeError, \
48 _("Symbol is invalid.")); \
49 return NULL; \
50 } \
51 } while (0)
52
53 static const struct objfile_data *sympy_objfile_data_key;
54
55 static PyObject *
56 sympy_str (PyObject *self)
57 {
58 PyObject *result;
59 struct symbol *symbol = NULL;
60
61 SYMPY_REQUIRE_VALID (self, symbol);
62
63 result = PyString_FromString (symbol->print_name ());
64
65 return result;
66 }
67
68 static PyObject *
69 sympy_get_type (PyObject *self, void *closure)
70 {
71 struct symbol *symbol = NULL;
72
73 SYMPY_REQUIRE_VALID (self, symbol);
74
75 if (SYMBOL_TYPE (symbol) == NULL)
76 {
77 Py_INCREF (Py_None);
78 return Py_None;
79 }
80
81 return type_to_type_object (SYMBOL_TYPE (symbol));
82 }
83
84 static PyObject *
85 sympy_get_symtab (PyObject *self, void *closure)
86 {
87 struct symbol *symbol = NULL;
88
89 SYMPY_REQUIRE_VALID (self, symbol);
90
91 if (!SYMBOL_OBJFILE_OWNED (symbol))
92 Py_RETURN_NONE;
93
94 return symtab_to_symtab_object (symbol_symtab (symbol));
95 }
96
97 static PyObject *
98 sympy_get_name (PyObject *self, void *closure)
99 {
100 struct symbol *symbol = NULL;
101
102 SYMPY_REQUIRE_VALID (self, symbol);
103
104 return PyString_FromString (symbol->natural_name ());
105 }
106
107 static PyObject *
108 sympy_get_linkage_name (PyObject *self, void *closure)
109 {
110 struct symbol *symbol = NULL;
111
112 SYMPY_REQUIRE_VALID (self, symbol);
113
114 return PyString_FromString (symbol->linkage_name ());
115 }
116
117 static PyObject *
118 sympy_get_print_name (PyObject *self, void *closure)
119 {
120 struct symbol *symbol = NULL;
121
122 SYMPY_REQUIRE_VALID (self, symbol);
123
124 return sympy_str (self);
125 }
126
127 static PyObject *
128 sympy_get_addr_class (PyObject *self, void *closure)
129 {
130 struct symbol *symbol = NULL;
131
132 SYMPY_REQUIRE_VALID (self, symbol);
133
134 return gdb_py_object_from_longest (SYMBOL_CLASS (symbol)).release ();
135 }
136
137 static PyObject *
138 sympy_is_argument (PyObject *self, void *closure)
139 {
140 struct symbol *symbol = NULL;
141
142 SYMPY_REQUIRE_VALID (self, symbol);
143
144 return PyBool_FromLong (SYMBOL_IS_ARGUMENT (symbol));
145 }
146
147 static PyObject *
148 sympy_is_constant (PyObject *self, void *closure)
149 {
150 struct symbol *symbol = NULL;
151 enum address_class theclass;
152
153 SYMPY_REQUIRE_VALID (self, symbol);
154
155 theclass = SYMBOL_CLASS (symbol);
156
157 return PyBool_FromLong (theclass == LOC_CONST || theclass == LOC_CONST_BYTES);
158 }
159
160 static PyObject *
161 sympy_is_function (PyObject *self, void *closure)
162 {
163 struct symbol *symbol = NULL;
164 enum address_class theclass;
165
166 SYMPY_REQUIRE_VALID (self, symbol);
167
168 theclass = SYMBOL_CLASS (symbol);
169
170 return PyBool_FromLong (theclass == LOC_BLOCK);
171 }
172
173 static PyObject *
174 sympy_is_variable (PyObject *self, void *closure)
175 {
176 struct symbol *symbol = NULL;
177 enum address_class theclass;
178
179 SYMPY_REQUIRE_VALID (self, symbol);
180
181 theclass = SYMBOL_CLASS (symbol);
182
183 return PyBool_FromLong (!SYMBOL_IS_ARGUMENT (symbol)
184 && (theclass == LOC_LOCAL || theclass == LOC_REGISTER
185 || theclass == LOC_STATIC || theclass == LOC_COMPUTED
186 || theclass == LOC_OPTIMIZED_OUT));
187 }
188
189 /* Implementation of gdb.Symbol.needs_frame -> Boolean.
190 Returns true iff the symbol needs a frame for evaluation. */
191
192 static PyObject *
193 sympy_needs_frame (PyObject *self, void *closure)
194 {
195 struct symbol *symbol = NULL;
196 int result = 0;
197
198 SYMPY_REQUIRE_VALID (self, symbol);
199
200 try
201 {
202 result = symbol_read_needs_frame (symbol);
203 }
204 catch (const gdb_exception &except)
205 {
206 GDB_PY_HANDLE_EXCEPTION (except);
207 }
208
209 if (result)
210 Py_RETURN_TRUE;
211 Py_RETURN_FALSE;
212 }
213
214 /* Implementation of gdb.Symbol.line -> int.
215 Returns the line number at which the symbol was defined. */
216
217 static PyObject *
218 sympy_line (PyObject *self, void *closure)
219 {
220 struct symbol *symbol = NULL;
221
222 SYMPY_REQUIRE_VALID (self, symbol);
223
224 return gdb_py_object_from_longest (SYMBOL_LINE (symbol)).release ();
225 }
226
227 /* Implementation of gdb.Symbol.is_valid (self) -> Boolean.
228 Returns True if this Symbol still exists in GDB. */
229
230 static PyObject *
231 sympy_is_valid (PyObject *self, PyObject *args)
232 {
233 struct symbol *symbol = NULL;
234
235 symbol = symbol_object_to_symbol (self);
236 if (symbol == NULL)
237 Py_RETURN_FALSE;
238
239 Py_RETURN_TRUE;
240 }
241
242 /* Implementation of gdb.Symbol.value (self[, frame]) -> gdb.Value. Returns
243 the value of the symbol, or an error in various circumstances. */
244
245 static PyObject *
246 sympy_value (PyObject *self, PyObject *args)
247 {
248 struct symbol *symbol = NULL;
249 struct frame_info *frame_info = NULL;
250 PyObject *frame_obj = NULL;
251 struct value *value = NULL;
252
253 if (!PyArg_ParseTuple (args, "|O", &frame_obj))
254 return NULL;
255
256 if (frame_obj != NULL && !PyObject_TypeCheck (frame_obj, &frame_object_type))
257 {
258 PyErr_SetString (PyExc_TypeError, "argument is not a frame");
259 return NULL;
260 }
261
262 SYMPY_REQUIRE_VALID (self, symbol);
263 if (SYMBOL_CLASS (symbol) == LOC_TYPEDEF)
264 {
265 PyErr_SetString (PyExc_TypeError, "cannot get the value of a typedef");
266 return NULL;
267 }
268
269 try
270 {
271 if (frame_obj != NULL)
272 {
273 frame_info = frame_object_to_frame_info (frame_obj);
274 if (frame_info == NULL)
275 error (_("invalid frame"));
276 }
277
278 if (symbol_read_needs_frame (symbol) && frame_info == NULL)
279 error (_("symbol requires a frame to compute its value"));
280
281 /* TODO: currently, we have no way to recover the block in which SYMBOL
282 was found, so we have no block to pass to read_var_value. This will
283 yield an incorrect value when symbol is not local to FRAME_INFO (this
284 can happen with nested functions). */
285 value = read_var_value (symbol, NULL, frame_info);
286 }
287 catch (const gdb_exception &except)
288 {
289 GDB_PY_HANDLE_EXCEPTION (except);
290 }
291
292 return value_to_value_object (value);
293 }
294
295 /* Given a symbol, and a symbol_object that has previously been
296 allocated and initialized, populate the symbol_object with the
297 struct symbol data. Also, register the symbol_object life-cycle
298 with the life-cycle of the object file associated with this
299 symbol, if needed. */
300 static void
301 set_symbol (symbol_object *obj, struct symbol *symbol)
302 {
303 obj->symbol = symbol;
304 obj->prev = NULL;
305 if (SYMBOL_OBJFILE_OWNED (symbol)
306 && symbol_symtab (symbol) != NULL)
307 {
308 struct objfile *objfile = symbol_objfile (symbol);
309
310 obj->next = ((symbol_object *)
311 objfile_data (objfile, sympy_objfile_data_key));
312 if (obj->next)
313 obj->next->prev = obj;
314 set_objfile_data (objfile, sympy_objfile_data_key, obj);
315 }
316 else
317 obj->next = NULL;
318 }
319
320 /* Create a new symbol object (gdb.Symbol) that encapsulates the struct
321 symbol object from GDB. */
322 PyObject *
323 symbol_to_symbol_object (struct symbol *sym)
324 {
325 symbol_object *sym_obj;
326
327 sym_obj = PyObject_New (symbol_object, &symbol_object_type);
328 if (sym_obj)
329 set_symbol (sym_obj, sym);
330
331 return (PyObject *) sym_obj;
332 }
333
334 /* Return the symbol that is wrapped by this symbol object. */
335 struct symbol *
336 symbol_object_to_symbol (PyObject *obj)
337 {
338 if (! PyObject_TypeCheck (obj, &symbol_object_type))
339 return NULL;
340 return ((symbol_object *) obj)->symbol;
341 }
342
343 static void
344 sympy_dealloc (PyObject *obj)
345 {
346 symbol_object *sym_obj = (symbol_object *) obj;
347
348 if (sym_obj->prev)
349 sym_obj->prev->next = sym_obj->next;
350 else if (sym_obj->symbol != NULL
351 && SYMBOL_OBJFILE_OWNED (sym_obj->symbol)
352 && symbol_symtab (sym_obj->symbol) != NULL)
353 {
354 set_objfile_data (symbol_objfile (sym_obj->symbol),
355 sympy_objfile_data_key, sym_obj->next);
356 }
357 if (sym_obj->next)
358 sym_obj->next->prev = sym_obj->prev;
359 sym_obj->symbol = NULL;
360 Py_TYPE (obj)->tp_free (obj);
361 }
362
363 /* Implementation of
364 gdb.lookup_symbol (name [, block] [, domain]) -> (symbol, is_field_of_this)
365 A tuple with 2 elements is always returned. The first is the symbol
366 object or None, the second is a boolean with the value of
367 is_a_field_of_this (see comment in lookup_symbol_in_language). */
368
369 PyObject *
370 gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw)
371 {
372 int domain = VAR_DOMAIN;
373 struct field_of_this_result is_a_field_of_this;
374 const char *name;
375 static const char *keywords[] = { "name", "block", "domain", NULL };
376 struct symbol *symbol = NULL;
377 PyObject *block_obj = NULL, *sym_obj, *bool_obj;
378 const struct block *block = NULL;
379
380 if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|O!i", keywords, &name,
381 &block_object_type, &block_obj,
382 &domain))
383 return NULL;
384
385 if (block_obj)
386 block = block_object_to_block (block_obj);
387 else
388 {
389 struct frame_info *selected_frame;
390
391 try
392 {
393 selected_frame = get_selected_frame (_("No frame selected."));
394 block = get_frame_block (selected_frame, NULL);
395 }
396 catch (const gdb_exception &except)
397 {
398 GDB_PY_HANDLE_EXCEPTION (except);
399 }
400 }
401
402 try
403 {
404 symbol = lookup_symbol (name, block, (domain_enum) domain,
405 &is_a_field_of_this).symbol;
406 }
407 catch (const gdb_exception &except)
408 {
409 GDB_PY_HANDLE_EXCEPTION (except);
410 }
411
412 gdbpy_ref<> ret_tuple (PyTuple_New (2));
413 if (ret_tuple == NULL)
414 return NULL;
415
416 if (symbol)
417 {
418 sym_obj = symbol_to_symbol_object (symbol);
419 if (!sym_obj)
420 return NULL;
421 }
422 else
423 {
424 sym_obj = Py_None;
425 Py_INCREF (Py_None);
426 }
427 PyTuple_SET_ITEM (ret_tuple.get (), 0, sym_obj);
428
429 bool_obj = (is_a_field_of_this.type != NULL) ? Py_True : Py_False;
430 Py_INCREF (bool_obj);
431 PyTuple_SET_ITEM (ret_tuple.get (), 1, bool_obj);
432
433 return ret_tuple.release ();
434 }
435
436 /* Implementation of
437 gdb.lookup_global_symbol (name [, domain]) -> symbol or None. */
438
439 PyObject *
440 gdbpy_lookup_global_symbol (PyObject *self, PyObject *args, PyObject *kw)
441 {
442 int domain = VAR_DOMAIN;
443 const char *name;
444 static const char *keywords[] = { "name", "domain", NULL };
445 struct symbol *symbol = NULL;
446 PyObject *sym_obj;
447
448 if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|i", keywords, &name,
449 &domain))
450 return NULL;
451
452 try
453 {
454 symbol = lookup_global_symbol (name, NULL, (domain_enum) domain).symbol;
455 }
456 catch (const gdb_exception &except)
457 {
458 GDB_PY_HANDLE_EXCEPTION (except);
459 }
460
461 if (symbol)
462 {
463 sym_obj = symbol_to_symbol_object (symbol);
464 if (!sym_obj)
465 return NULL;
466 }
467 else
468 {
469 sym_obj = Py_None;
470 Py_INCREF (Py_None);
471 }
472
473 return sym_obj;
474 }
475
476 /* Implementation of
477 gdb.lookup_static_symbol (name [, domain]) -> symbol or None. */
478
479 PyObject *
480 gdbpy_lookup_static_symbol (PyObject *self, PyObject *args, PyObject *kw)
481 {
482 const char *name;
483 int domain = VAR_DOMAIN;
484 static const char *keywords[] = { "name", "domain", NULL };
485 struct symbol *symbol = NULL;
486 PyObject *sym_obj;
487
488 if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|i", keywords, &name,
489 &domain))
490 return NULL;
491
492 /* In order to find static symbols associated with the "current" object
493 file ahead of those from other object files, we first need to see if
494 we can acquire a current block. If this fails however, then we still
495 want to search all static symbols, so don't throw an exception just
496 yet. */
497 const struct block *block = NULL;
498 try
499 {
500 struct frame_info *selected_frame
501 = get_selected_frame (_("No frame selected."));
502 block = get_frame_block (selected_frame, NULL);
503 }
504 catch (const gdb_exception &except)
505 {
506 /* Nothing. */
507 }
508
509 try
510 {
511 if (block != nullptr)
512 symbol
513 = lookup_symbol_in_static_block (name, block,
514 (domain_enum) domain).symbol;
515
516 if (symbol == nullptr)
517 symbol = lookup_static_symbol (name, (domain_enum) domain).symbol;
518 }
519 catch (const gdb_exception &except)
520 {
521 GDB_PY_HANDLE_EXCEPTION (except);
522 }
523
524 if (symbol)
525 {
526 sym_obj = symbol_to_symbol_object (symbol);
527 if (!sym_obj)
528 return NULL;
529 }
530 else
531 {
532 sym_obj = Py_None;
533 Py_INCREF (Py_None);
534 }
535
536 return sym_obj;
537 }
538
539 /* Implementation of
540 gdb.lookup_static_symbols (name [, domain]) -> symbol list.
541
542 Returns a list of all static symbols matching NAME in DOMAIN. */
543
544 PyObject *
545 gdbpy_lookup_static_symbols (PyObject *self, PyObject *args, PyObject *kw)
546 {
547 const char *name;
548 int domain = VAR_DOMAIN;
549 static const char *keywords[] = { "name", "domain", NULL };
550
551 if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|i", keywords, &name,
552 &domain))
553 return NULL;
554
555 gdbpy_ref<> return_list (PyList_New (0));
556 if (return_list == NULL)
557 return NULL;
558
559 try
560 {
561 /* Expand any symtabs that contain potentially matching symbols. */
562 lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
563 expand_symtabs_matching (NULL, lookup_name, NULL, NULL,
564 SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK,
565 ALL_DOMAIN);
566
567 for (objfile *objfile : current_program_space->objfiles ())
568 {
569 for (compunit_symtab *cust : objfile->compunits ())
570 {
571 const struct blockvector *bv;
572 const struct block *block;
573
574 bv = COMPUNIT_BLOCKVECTOR (cust);
575 block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
576
577 if (block != nullptr)
578 {
579 symbol *symbol = lookup_symbol_in_static_block
580 (name, block, (domain_enum) domain).symbol;
581
582 if (symbol != nullptr)
583 {
584 PyObject *sym_obj
585 = symbol_to_symbol_object (symbol);
586 if (PyList_Append (return_list.get (), sym_obj) == -1)
587 return NULL;
588 }
589 }
590 }
591 }
592 }
593 catch (const gdb_exception &except)
594 {
595 GDB_PY_HANDLE_EXCEPTION (except);
596 }
597
598 return return_list.release ();
599 }
600
601 /* This function is called when an objfile is about to be freed.
602 Invalidate the symbol as further actions on the symbol would result
603 in bad data. All access to obj->symbol should be gated by
604 SYMPY_REQUIRE_VALID which will raise an exception on invalid
605 symbols. */
606 static void
607 del_objfile_symbols (struct objfile *objfile, void *datum)
608 {
609 symbol_object *obj = (symbol_object *) datum;
610 while (obj)
611 {
612 symbol_object *next = obj->next;
613
614 obj->symbol = NULL;
615 obj->next = NULL;
616 obj->prev = NULL;
617
618 obj = next;
619 }
620 }
621
622 void _initialize_py_symbol ();
623 void
624 _initialize_py_symbol ()
625 {
626 /* Register an objfile "free" callback so we can properly
627 invalidate symbol when an object file that is about to be
628 deleted. */
629 sympy_objfile_data_key
630 = register_objfile_data_with_cleanup (NULL, del_objfile_symbols);
631 }
632
633 int
634 gdbpy_initialize_symbols (void)
635 {
636 if (PyType_Ready (&symbol_object_type) < 0)
637 return -1;
638
639 if (PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_UNDEF", LOC_UNDEF) < 0
640 || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_CONST",
641 LOC_CONST) < 0
642 || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_STATIC",
643 LOC_STATIC) < 0
644 || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REGISTER",
645 LOC_REGISTER) < 0
646 || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_ARG",
647 LOC_ARG) < 0
648 || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REF_ARG",
649 LOC_REF_ARG) < 0
650 || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_LOCAL",
651 LOC_LOCAL) < 0
652 || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_TYPEDEF",
653 LOC_TYPEDEF) < 0
654 || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_LABEL",
655 LOC_LABEL) < 0
656 || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_BLOCK",
657 LOC_BLOCK) < 0
658 || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_CONST_BYTES",
659 LOC_CONST_BYTES) < 0
660 || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_UNRESOLVED",
661 LOC_UNRESOLVED) < 0
662 || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_OPTIMIZED_OUT",
663 LOC_OPTIMIZED_OUT) < 0
664 || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_COMPUTED",
665 LOC_COMPUTED) < 0
666 || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_COMMON_BLOCK",
667 LOC_COMMON_BLOCK) < 0
668 || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REGPARM_ADDR",
669 LOC_REGPARM_ADDR) < 0
670 || PyModule_AddIntConstant (gdb_module, "SYMBOL_UNDEF_DOMAIN",
671 UNDEF_DOMAIN) < 0
672 || PyModule_AddIntConstant (gdb_module, "SYMBOL_VAR_DOMAIN",
673 VAR_DOMAIN) < 0
674 || PyModule_AddIntConstant (gdb_module, "SYMBOL_STRUCT_DOMAIN",
675 STRUCT_DOMAIN) < 0
676 || PyModule_AddIntConstant (gdb_module, "SYMBOL_LABEL_DOMAIN",
677 LABEL_DOMAIN) < 0
678 || PyModule_AddIntConstant (gdb_module, "SYMBOL_MODULE_DOMAIN",
679 MODULE_DOMAIN) < 0
680 || PyModule_AddIntConstant (gdb_module, "SYMBOL_COMMON_BLOCK_DOMAIN",
681 COMMON_BLOCK_DOMAIN) < 0)
682 return -1;
683
684 /* These remain defined for compatibility, but as they were never
685 correct, they are no longer documented. Eventually we can remove
686 them. These exist because at one time, enum search_domain and
687 enum domain_enum_tag were combined -- but different values were
688 used differently. Here we try to give them values that will make
689 sense if they are passed to gdb.lookup_symbol. */
690 if (PyModule_AddIntConstant (gdb_module, "SYMBOL_VARIABLES_DOMAIN",
691 VAR_DOMAIN) < 0
692 || PyModule_AddIntConstant (gdb_module, "SYMBOL_FUNCTIONS_DOMAIN",
693 VAR_DOMAIN) < 0
694 || PyModule_AddIntConstant (gdb_module, "SYMBOL_TYPES_DOMAIN",
695 VAR_DOMAIN) < 0)
696 return -1;
697
698 return gdb_pymodule_addobject (gdb_module, "Symbol",
699 (PyObject *) &symbol_object_type);
700 }
701
702 \f
703
704 static gdb_PyGetSetDef symbol_object_getset[] = {
705 { "type", sympy_get_type, NULL,
706 "Type of the symbol.", NULL },
707 { "symtab", sympy_get_symtab, NULL,
708 "Symbol table in which the symbol appears.", NULL },
709 { "name", sympy_get_name, NULL,
710 "Name of the symbol, as it appears in the source code.", NULL },
711 { "linkage_name", sympy_get_linkage_name, NULL,
712 "Name of the symbol, as used by the linker (i.e., may be mangled).",
713 NULL },
714 { "print_name", sympy_get_print_name, NULL,
715 "Name of the symbol in a form suitable for output.\n\
716 This is either name or linkage_name, depending on whether the user asked GDB\n\
717 to display demangled or mangled names.", NULL },
718 { "addr_class", sympy_get_addr_class, NULL, "Address class of the symbol." },
719 { "is_argument", sympy_is_argument, NULL,
720 "True if the symbol is an argument of a function." },
721 { "is_constant", sympy_is_constant, NULL,
722 "True if the symbol is a constant." },
723 { "is_function", sympy_is_function, NULL,
724 "True if the symbol is a function or method." },
725 { "is_variable", sympy_is_variable, NULL,
726 "True if the symbol is a variable." },
727 { "needs_frame", sympy_needs_frame, NULL,
728 "True if the symbol requires a frame for evaluation." },
729 { "line", sympy_line, NULL,
730 "The source line number at which the symbol was defined." },
731 { NULL } /* Sentinel */
732 };
733
734 static PyMethodDef symbol_object_methods[] = {
735 { "is_valid", sympy_is_valid, METH_NOARGS,
736 "is_valid () -> Boolean.\n\
737 Return true if this symbol is valid, false if not." },
738 { "value", sympy_value, METH_VARARGS,
739 "value ([frame]) -> gdb.Value\n\
740 Return the value of the symbol." },
741 {NULL} /* Sentinel */
742 };
743
744 PyTypeObject symbol_object_type = {
745 PyVarObject_HEAD_INIT (NULL, 0)
746 "gdb.Symbol", /*tp_name*/
747 sizeof (symbol_object), /*tp_basicsize*/
748 0, /*tp_itemsize*/
749 sympy_dealloc, /*tp_dealloc*/
750 0, /*tp_print*/
751 0, /*tp_getattr*/
752 0, /*tp_setattr*/
753 0, /*tp_compare*/
754 0, /*tp_repr*/
755 0, /*tp_as_number*/
756 0, /*tp_as_sequence*/
757 0, /*tp_as_mapping*/
758 0, /*tp_hash */
759 0, /*tp_call*/
760 sympy_str, /*tp_str*/
761 0, /*tp_getattro*/
762 0, /*tp_setattro*/
763 0, /*tp_as_buffer*/
764 Py_TPFLAGS_DEFAULT, /*tp_flags*/
765 "GDB symbol object", /*tp_doc */
766 0, /*tp_traverse */
767 0, /*tp_clear */
768 0, /*tp_richcompare */
769 0, /*tp_weaklistoffset */
770 0, /*tp_iter */
771 0, /*tp_iternext */
772 symbol_object_methods, /*tp_methods */
773 0, /*tp_members */
774 symbol_object_getset /*tp_getset */
775 };