OLD | NEW |
1 /* Python interface to symbol tables. | 1 /* Python interface to symbol tables. |
2 | 2 |
3 Copyright (C) 2008-2012 Free Software Foundation, Inc. | 3 Copyright (C) 2008-2012 Free Software Foundation, Inc. |
4 | 4 |
5 This file is part of GDB. | 5 This file is part of GDB. |
6 | 6 |
7 This program is free software; you can redistribute it and/or modify | 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 | 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 | 9 the Free Software Foundation; either version 3 of the License, or |
10 (at your option) any later version. | 10 (at your option) any later version. |
11 | 11 |
12 This program is distributed in the hope that it will be useful, | 12 This program is distributed in the hope that it will be useful, |
13 but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 GNU General Public License for more details. | 15 GNU General Public License for more details. |
16 | 16 |
17 You should have received a copy of the GNU General Public License | 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/>. */ | 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
19 | 19 |
20 #include "defs.h" | 20 #include "defs.h" |
21 #include "charset.h" | 21 #include "charset.h" |
22 #include "symtab.h" | 22 #include "symtab.h" |
23 #include "source.h" | 23 #include "source.h" |
24 #include "python-internal.h" | 24 #include "python-internal.h" |
25 #include "objfiles.h" | 25 #include "objfiles.h" |
| 26 #include "block.h" |
26 | 27 |
27 typedef struct stpy_symtab_object { | 28 typedef struct stpy_symtab_object { |
28 PyObject_HEAD | 29 PyObject_HEAD |
29 /* The GDB Symbol table structure. */ | 30 /* The GDB Symbol table structure. */ |
30 struct symtab *symtab; | 31 struct symtab *symtab; |
31 /* A symtab object is associated with an objfile, so keep track with | 32 /* A symtab object is associated with an objfile, so keep track with |
32 a doubly-linked list, rooted in the objfile. This allows | 33 a doubly-linked list, rooted in the objfile. This allows |
33 invalidation of the underlying struct symtab when the objfile is | 34 invalidation of the underlying struct symtab when the objfile is |
34 deleted. */ | 35 deleted. */ |
35 struct stpy_symtab_object *prev; | 36 struct stpy_symtab_object *prev; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 { | 147 { |
147 struct symtab *symtab = NULL; | 148 struct symtab *symtab = NULL; |
148 | 149 |
149 symtab = symtab_object_to_symtab (self); | 150 symtab = symtab_object_to_symtab (self); |
150 if (symtab == NULL) | 151 if (symtab == NULL) |
151 Py_RETURN_FALSE; | 152 Py_RETURN_FALSE; |
152 | 153 |
153 Py_RETURN_TRUE; | 154 Py_RETURN_TRUE; |
154 } | 155 } |
155 | 156 |
| 157 /* Return the GLOBAL_BLOCK of the underlying symtab. */ |
| 158 |
| 159 static PyObject * |
| 160 stpy_global_block (PyObject *self, PyObject *args) |
| 161 { |
| 162 struct symtab *symtab = NULL; |
| 163 struct block *block = NULL; |
| 164 struct blockvector *blockvector; |
| 165 |
| 166 STPY_REQUIRE_VALID (self, symtab); |
| 167 |
| 168 blockvector = BLOCKVECTOR (symtab); |
| 169 block = BLOCKVECTOR_BLOCK (blockvector, GLOBAL_BLOCK); |
| 170 return block_to_block_object (block, symtab->objfile); |
| 171 } |
| 172 |
| 173 /* Return the STATIC_BLOCK of the underlying symtab. */ |
| 174 |
| 175 static PyObject * |
| 176 stpy_static_block (PyObject *self, PyObject *args) |
| 177 { |
| 178 struct symtab *symtab = NULL; |
| 179 struct block *block = NULL; |
| 180 struct blockvector *blockvector; |
| 181 |
| 182 STPY_REQUIRE_VALID (self, symtab); |
| 183 |
| 184 blockvector = BLOCKVECTOR (symtab); |
| 185 block = BLOCKVECTOR_BLOCK (blockvector, STATIC_BLOCK); |
| 186 return block_to_block_object (block, symtab->objfile); |
| 187 } |
| 188 |
156 static PyObject * | 189 static PyObject * |
157 salpy_str (PyObject *self) | 190 salpy_str (PyObject *self) |
158 { | 191 { |
159 char *s, *filename; | 192 char *s, *filename; |
160 sal_object *sal_obj; | 193 sal_object *sal_obj; |
161 PyObject *result; | 194 PyObject *result; |
162 struct symtab_and_line *sal = NULL; | 195 struct symtab_and_line *sal = NULL; |
163 | 196 |
164 SALPY_REQUIRE_VALID (self, sal); | 197 SALPY_REQUIRE_VALID (self, sal); |
165 | 198 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 static PyObject * | 230 static PyObject * |
198 salpy_get_pc (PyObject *self, void *closure) | 231 salpy_get_pc (PyObject *self, void *closure) |
199 { | 232 { |
200 struct symtab_and_line *sal = NULL; | 233 struct symtab_and_line *sal = NULL; |
201 | 234 |
202 SALPY_REQUIRE_VALID (self, sal); | 235 SALPY_REQUIRE_VALID (self, sal); |
203 | 236 |
204 return gdb_py_long_from_ulongest (sal->pc); | 237 return gdb_py_long_from_ulongest (sal->pc); |
205 } | 238 } |
206 | 239 |
| 240 /* Implementation of the get method for the 'last' attribute of |
| 241 gdb.Symtab_and_line. */ |
| 242 |
| 243 static PyObject * |
| 244 salpy_get_last (PyObject *self, void *closure) |
| 245 { |
| 246 struct symtab_and_line *sal = NULL; |
| 247 |
| 248 SALPY_REQUIRE_VALID (self, sal); |
| 249 |
| 250 if (sal->end > 0) |
| 251 return gdb_py_long_from_ulongest (sal->end - 1); |
| 252 else |
| 253 Py_RETURN_NONE; |
| 254 } |
| 255 |
207 static PyObject * | 256 static PyObject * |
208 salpy_get_line (PyObject *self, void *closure) | 257 salpy_get_line (PyObject *self, void *closure) |
209 { | 258 { |
210 struct symtab_and_line *sal = NULL; | 259 struct symtab_and_line *sal = NULL; |
211 | 260 |
212 SALPY_REQUIRE_VALID (self, sal); | 261 SALPY_REQUIRE_VALID (self, sal); |
213 | 262 |
214 return PyInt_FromLong (sal->line); | 263 return PyInt_FromLong (sal->line); |
215 } | 264 } |
216 | 265 |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 { "filename", stpy_get_filename, NULL, | 516 { "filename", stpy_get_filename, NULL, |
468 "The symbol table's source filename.", NULL }, | 517 "The symbol table's source filename.", NULL }, |
469 { "objfile", stpy_get_objfile, NULL, "The symtab's objfile.", | 518 { "objfile", stpy_get_objfile, NULL, "The symtab's objfile.", |
470 NULL }, | 519 NULL }, |
471 {NULL} /* Sentinel */ | 520 {NULL} /* Sentinel */ |
472 }; | 521 }; |
473 | 522 |
474 static PyMethodDef symtab_object_methods[] = { | 523 static PyMethodDef symtab_object_methods[] = { |
475 { "is_valid", stpy_is_valid, METH_NOARGS, | 524 { "is_valid", stpy_is_valid, METH_NOARGS, |
476 "is_valid () -> Boolean.\n\ | 525 "is_valid () -> Boolean.\n\ |
error: old chunk mismatch |
None
OLD | NEW |