Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: gdb/python/py-symtab.c

Issue 124383005: GDB 7.6.50 (Closed) Base URL: http://git.chromium.org/native_client/nacl-gdb.git@upstream
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gdb/python/py-symbol.c ('k') | gdb/python/py-threadevent.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
None
OLDNEW
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-2013 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
(...skipping 16 matching lines...) Expand all
30 /* The GDB Symbol table structure. */ 30 /* The GDB Symbol table structure. */
31 struct symtab *symtab; 31 struct symtab *symtab;
32 /* 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
33 a doubly-linked list, rooted in the objfile. This allows 33 a doubly-linked list, rooted in the objfile. This allows
34 invalidation of the underlying struct symtab when the objfile is 34 invalidation of the underlying struct symtab when the objfile is
35 deleted. */ 35 deleted. */
36 struct stpy_symtab_object *prev; 36 struct stpy_symtab_object *prev;
37 struct stpy_symtab_object *next; 37 struct stpy_symtab_object *next;
38 } symtab_object; 38 } symtab_object;
39 39
40 static PyTypeObject symtab_object_type; 40 static PyTypeObject symtab_object_type
41 CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("symtab_object");
41 static const struct objfile_data *stpy_objfile_data_key; 42 static const struct objfile_data *stpy_objfile_data_key;
42 43
43 /* Require a valid symbol table. All access to symtab_object->symtab 44 /* Require a valid symbol table. All access to symtab_object->symtab
44 should be gated by this call. */ 45 should be gated by this call. */
45 #define STPY_REQUIRE_VALID(symtab_obj, symtab) \ 46 #define STPY_REQUIRE_VALID(symtab_obj, symtab) \
46 do { \ 47 do { \
47 symtab = symtab_object_to_symtab (symtab_obj); \ 48 symtab = symtab_object_to_symtab (symtab_obj); \
48 if (symtab == NULL) \ 49 if (symtab == NULL) \
49 { \ 50 { \
50 PyErr_SetString (PyExc_RuntimeError, \ 51 PyErr_SetString (PyExc_RuntimeError, \
51 _("Symbol Table is invalid.")); \ 52 _("Symbol Table is invalid.")); \
52 return NULL; \ 53 return NULL; \
53 } \ 54 } \
54 } while (0) 55 } while (0)
55 56
56 typedef struct salpy_sal_object { 57 typedef struct salpy_sal_object {
57 PyObject_HEAD 58 PyObject_HEAD
58 /* The GDB Symbol table structure. */ 59 /* The GDB Symbol table structure. */
59 symtab_object *symtab; 60 symtab_object *symtab;
60 /* The GDB Symbol table and line structure. */ 61 /* The GDB Symbol table and line structure. */
61 struct symtab_and_line *sal; 62 struct symtab_and_line *sal;
62 /* A Symtab and line object is associated with an objfile, so keep 63 /* A Symtab and line object is associated with an objfile, so keep
63 track with a doubly-linked list, rooted in the objfile. This 64 track with a doubly-linked list, rooted in the objfile. This
64 allows invalidation of the underlying struct symtab_and_line 65 allows invalidation of the underlying struct symtab_and_line
65 when the objfile is deleted. */ 66 when the objfile is deleted. */
66 struct salpy_sal_object *prev; 67 struct salpy_sal_object *prev;
67 struct salpy_sal_object *next; 68 struct salpy_sal_object *next;
68 } sal_object; 69 } sal_object;
69 70
70 static PyTypeObject sal_object_type; 71 static PyTypeObject sal_object_type
72 CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("sal_object");
71 static const struct objfile_data *salpy_objfile_data_key; 73 static const struct objfile_data *salpy_objfile_data_key;
72 74
73 /* Require a valid symbol table and line object. All access to 75 /* Require a valid symbol table and line object. All access to
74 sal_object->sal should be gated by this call. */ 76 sal_object->sal should be gated by this call. */
75 #define SALPY_REQUIRE_VALID(sal_obj, sal) \ 77 #define SALPY_REQUIRE_VALID(sal_obj, sal) \
76 do { \ 78 do { \
77 sal = sal_object_to_symtab_and_line (sal_obj); \ 79 sal = sal_object_to_symtab_and_line (sal_obj); \
78 if (sal == NULL) \ 80 if (sal == NULL) \
79 { \ 81 { \
80 PyErr_SetString (PyExc_RuntimeError, \ 82 PyErr_SetString (PyExc_RuntimeError, \
81 _("Symbol Table and Line is invalid.")); \ 83 _("Symbol Table and Line is invalid.")); \
82 return NULL; \ 84 return NULL; \
83 } \ 85 } \
84 } while (0) 86 } while (0)
85 87
86 static PyObject * 88 static PyObject *
87 stpy_str (PyObject *self) 89 stpy_str (PyObject *self)
88 { 90 {
89 PyObject *result; 91 PyObject *result;
90 struct symtab *symtab = NULL; 92 struct symtab *symtab = NULL;
91 93
92 STPY_REQUIRE_VALID (self, symtab); 94 STPY_REQUIRE_VALID (self, symtab);
93 95
94 result = PyString_FromString (symtab->filename); 96 result = PyString_FromString (symtab_to_filename_for_display (symtab));
95 97
96 return result; 98 return result;
97 } 99 }
98 100
99 static PyObject * 101 static PyObject *
100 stpy_get_filename (PyObject *self, void *closure) 102 stpy_get_filename (PyObject *self, void *closure)
101 { 103 {
102 PyObject *str_obj; 104 PyObject *str_obj;
103 struct symtab *symtab = NULL; 105 struct symtab *symtab = NULL;
106 const char *filename;
104 107
105 STPY_REQUIRE_VALID (self, symtab); 108 STPY_REQUIRE_VALID (self, symtab);
109 filename = symtab_to_filename_for_display (symtab);
106 110
107 str_obj = PyString_Decode (symtab->filename, 111 str_obj = PyString_Decode (filename, strlen (filename),
108 » » » strlen (symtab->filename),
109 host_charset (), NULL); 112 host_charset (), NULL);
110 return str_obj; 113 return str_obj;
111 } 114 }
112 115
113 static PyObject * 116 static PyObject *
114 stpy_get_objfile (PyObject *self, void *closure) 117 stpy_get_objfile (PyObject *self, void *closure)
115 { 118 {
116 struct symtab *symtab = NULL; 119 struct symtab *symtab = NULL;
117 PyObject *result; 120 PyObject *result;
118 121
119 STPY_REQUIRE_VALID (self, symtab); 122 STPY_REQUIRE_VALID (self, symtab);
120 123
121 result = objfile_to_objfile_object (symtab->objfile); 124 result = objfile_to_objfile_object (symtab->objfile);
122 Py_XINCREF (result); 125 Py_XINCREF (result);
123 return result; 126 return result;
124 } 127 }
125 128
126 static PyObject * 129 static PyObject *
127 stpy_fullname (PyObject *self, PyObject *args) 130 stpy_fullname (PyObject *self, PyObject *args)
128 { 131 {
129 char *fullname; 132 const char *fullname;
130 struct symtab *symtab = NULL; 133 struct symtab *symtab = NULL;
131 134
132 STPY_REQUIRE_VALID (self, symtab); 135 STPY_REQUIRE_VALID (self, symtab);
133 136
134 fullname = symtab_to_fullname (symtab); 137 fullname = symtab_to_fullname (symtab);
135 if (fullname)
136 return PyString_Decode (fullname, strlen (fullname),
137 host_charset (), NULL);
138 138
139 Py_RETURN_NONE; 139 return PyString_Decode (fullname, strlen (fullname), host_charset (), NULL);
140 } 140 }
141 141
142 /* Implementation of gdb.Symtab.is_valid (self) -> Boolean. 142 /* Implementation of gdb.Symtab.is_valid (self) -> Boolean.
143 Returns True if this Symbol table still exists in GDB. */ 143 Returns True if this Symbol table still exists in GDB. */
144 144
145 static PyObject * 145 static PyObject *
146 stpy_is_valid (PyObject *self, PyObject *args) 146 stpy_is_valid (PyObject *self, PyObject *args)
147 { 147 {
148 struct symtab *symtab = NULL; 148 struct symtab *symtab = NULL;
149 149
(...skipping 29 matching lines...) Expand all
179 struct block *block = NULL; 179 struct block *block = NULL;
180 struct blockvector *blockvector; 180 struct blockvector *blockvector;
181 181
182 STPY_REQUIRE_VALID (self, symtab); 182 STPY_REQUIRE_VALID (self, symtab);
183 183
184 blockvector = BLOCKVECTOR (symtab); 184 blockvector = BLOCKVECTOR (symtab);
185 block = BLOCKVECTOR_BLOCK (blockvector, STATIC_BLOCK); 185 block = BLOCKVECTOR_BLOCK (blockvector, STATIC_BLOCK);
186 return block_to_block_object (block, symtab->objfile); 186 return block_to_block_object (block, symtab->objfile);
187 } 187 }
188 188
189 /* Implementation of gdb.Symtab.linetable (self) -> gdb.Linetable.
190 Returns a gdb.Linetable object corresponding to this symbol
191 table. */
192
193 static PyObject *
194 stpy_get_linetable (PyObject *self, PyObject *args)
195 {
196 struct symtab *symtab = NULL;
197
198 STPY_REQUIRE_VALID (self, symtab);
199
200 return symtab_to_linetable_object (self);
201 }
202
189 static PyObject * 203 static PyObject *
190 salpy_str (PyObject *self) 204 salpy_str (PyObject *self)
191 { 205 {
192 char *s, *filename; 206 char *s;
207 const char *filename;
193 sal_object *sal_obj; 208 sal_object *sal_obj;
194 PyObject *result; 209 PyObject *result;
195 struct symtab_and_line *sal = NULL; 210 struct symtab_and_line *sal = NULL;
196 211
197 SALPY_REQUIRE_VALID (self, sal); 212 SALPY_REQUIRE_VALID (self, sal);
198 213
199 sal_obj = (sal_object *) self; 214 sal_obj = (sal_object *) self;
200 filename = (sal_obj->symtab == (symtab_object *) Py_None) 215 filename = (sal_obj->symtab == (symtab_object *) Py_None)
201 ? "<unknown>" : sal_obj->symtab->symtab->filename; 216 ? "<unknown>" : symtab_to_filename_for_display (sal_obj->symtab->symtab);
202 217
203 s = xstrprintf ("symbol and line for %s, line %d", filename, 218 s = xstrprintf ("symbol and line for %s, line %d", filename,
204 sal->line); 219 sal->line);
205 220
206 result = PyString_FromString (s); 221 result = PyString_FromString (s);
207 xfree (s); 222 xfree (s);
208 223
209 return result; 224 return result;
210 } 225 }
211 226
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 self_sal->prev->next = self_sal->next; 315 self_sal->prev->next = self_sal->next;
301 else if (self_sal->symtab != (symtab_object * ) Py_None) 316 else if (self_sal->symtab != (symtab_object * ) Py_None)
302 set_objfile_data (self_sal->symtab->symtab->objfile, 317 set_objfile_data (self_sal->symtab->symtab->objfile,
303 salpy_objfile_data_key, self_sal->next); 318 salpy_objfile_data_key, self_sal->next);
304 319
305 if (self_sal->next) 320 if (self_sal->next)
306 self_sal->next->prev = self_sal->prev; 321 self_sal->next->prev = self_sal->prev;
307 322
308 Py_DECREF (self_sal->symtab); 323 Py_DECREF (self_sal->symtab);
309 xfree (self_sal->sal); 324 xfree (self_sal->sal);
310 self_sal->ob_type->tp_free (self); 325 Py_TYPE (self)->tp_free (self);
311 } 326 }
312 327
313 /* Given a sal, and a sal_object that has previously been allocated 328 /* Given a sal, and a sal_object that has previously been allocated
314 and initialized, populate the sal_object with the struct sal data. 329 and initialized, populate the sal_object with the struct sal data.
315 Also, register the sal_object life-cycle with the life-cycle of the 330 Also, register the sal_object life-cycle with the life-cycle of the
316 object file associated with this sal, if needed. If a failure 331 object file associated with this sal, if needed. If a failure
317 occurs during the sal population, this function will return 332 occurs during the sal population, this function will return -1. */
318 NULL. */ 333 static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
319 static int
320 set_sal (sal_object *sal_obj, struct symtab_and_line sal) 334 set_sal (sal_object *sal_obj, struct symtab_and_line sal)
321 { 335 {
322 symtab_object *symtab_obj; 336 symtab_object *symtab_obj;
323 337
324 if (sal.symtab) 338 if (sal.symtab)
325 { 339 {
326 symtab_obj = (symtab_object *) symtab_to_symtab_object (sal.symtab); 340 symtab_obj = (symtab_object *) symtab_to_symtab_object (sal.symtab);
327 /* If a symtab existed in the sal, but it cannot be duplicated, 341 /* If a symtab existed in the sal, but it cannot be duplicated,
328 we exit. */ 342 we exit. */
329 if (symtab_obj == NULL) 343 if (symtab_obj == NULL)
330 » return 0; 344 » return -1;
331 } 345 }
332 else 346 else
333 { 347 {
334 symtab_obj = (symtab_object *) Py_None; 348 symtab_obj = (symtab_object *) Py_None;
335 Py_INCREF (Py_None); 349 Py_INCREF (Py_None);
336 } 350 }
337 351
338 sal_obj->sal = xmemdup (&sal, sizeof (struct symtab_and_line), 352 sal_obj->sal = xmemdup (&sal, sizeof (struct symtab_and_line),
339 sizeof (struct symtab_and_line)); 353 sizeof (struct symtab_and_line));
340 sal_obj->symtab = symtab_obj; 354 sal_obj->symtab = symtab_obj;
341 sal_obj->prev = NULL; 355 sal_obj->prev = NULL;
342 356
343 /* If the SAL does not have a symtab, we do not add it to the 357 /* If the SAL does not have a symtab, we do not add it to the
344 objfile cleanup observer linked list. */ 358 objfile cleanup observer linked list. */
345 if (sal_obj->symtab != (symtab_object *)Py_None) 359 if (sal_obj->symtab != (symtab_object *)Py_None)
346 { 360 {
347 sal_obj->next = objfile_data (sal_obj->symtab->symtab->objfile, 361 sal_obj->next = objfile_data (sal_obj->symtab->symtab->objfile,
348 salpy_objfile_data_key); 362 salpy_objfile_data_key);
349 if (sal_obj->next) 363 if (sal_obj->next)
350 sal_obj->next->prev = sal_obj; 364 sal_obj->next->prev = sal_obj;
351 365
352 set_objfile_data (sal_obj->symtab->symtab->objfile, 366 set_objfile_data (sal_obj->symtab->symtab->objfile,
353 salpy_objfile_data_key, sal_obj); 367 salpy_objfile_data_key, sal_obj);
354 } 368 }
355 else 369 else
356 sal_obj->next = NULL; 370 sal_obj->next = NULL;
357 371
358 return 1; 372 return 0;
359 } 373 }
360 374
361 /* Given a symtab, and a symtab_object that has previously been 375 /* Given a symtab, and a symtab_object that has previously been
362 allocated and initialized, populate the symtab_object with the 376 allocated and initialized, populate the symtab_object with the
363 struct symtab data. Also, register the symtab_object life-cycle 377 struct symtab data. Also, register the symtab_object life-cycle
364 with the life-cycle of the object file associated with this 378 with the life-cycle of the object file associated with this
365 symtab, if needed. */ 379 symtab, if needed. */
366 static void 380 static void
367 set_symtab (symtab_object *obj, struct symtab *symtab) 381 set_symtab (symtab_object *obj, struct symtab *symtab)
368 { 382 {
(...skipping 21 matching lines...) Expand all
390 if (symtab_obj) 404 if (symtab_obj)
391 set_symtab (symtab_obj, symtab); 405 set_symtab (symtab_obj, symtab);
392 406
393 return (PyObject *) symtab_obj; 407 return (PyObject *) symtab_obj;
394 } 408 }
395 409
396 /* Create a new symtab and line (gdb.Symtab_and_line) object 410 /* Create a new symtab and line (gdb.Symtab_and_line) object
397 that encapsulates the symtab_and_line structure from GDB. */ 411 that encapsulates the symtab_and_line structure from GDB. */
398 PyObject * 412 PyObject *
399 symtab_and_line_to_sal_object (struct symtab_and_line sal) 413 symtab_and_line_to_sal_object (struct symtab_and_line sal)
400
401 { 414 {
402 sal_object *sal_obj; 415 sal_object *sal_obj;
403 int success = 0; 416 int success = 0;
404 417
405 sal_obj = PyObject_New (sal_object, &sal_object_type); 418 sal_obj = PyObject_New (sal_object, &sal_object_type);
406 if (sal_obj) 419 if (sal_obj)
407 { 420 {
408 success = set_sal (sal_obj, sal); 421 if (set_sal (sal_obj, sal) < 0)
409 if (!success)
410 { 422 {
411 Py_DECREF (sal_obj); 423 Py_DECREF (sal_obj);
412 return NULL; 424 return NULL;
413 } 425 }
414 } 426 }
415 427
416 return (PyObject *) sal_obj; 428 return (PyObject *) sal_obj;
417 } 429 }
418 430
419 /* Return struct symtab_and_line reference that is wrapped by this 431 /* Return struct symtab_and_line reference that is wrapped by this
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 invalid symbol table and line objects. */ 475 invalid symbol table and line objects. */
464 static void 476 static void
465 del_objfile_sal (struct objfile *objfile, void *datum) 477 del_objfile_sal (struct objfile *objfile, void *datum)
466 { 478 {
467 sal_object *obj = datum; 479 sal_object *obj = datum;
468 480
469 while (obj) 481 while (obj)
470 { 482 {
471 sal_object *next = obj->next; 483 sal_object *next = obj->next;
472 484
473 obj->symtab = NULL; 485 Py_DECREF (obj->symtab);
486 obj->symtab = (symtab_object *) Py_None;
487 Py_INCREF (Py_None);
488
474 obj->next = NULL; 489 obj->next = NULL;
475 obj->prev = NULL; 490 obj->prev = NULL;
476 xfree (obj->sal); 491 xfree (obj->sal);
477 obj->sal = NULL; 492 obj->sal = NULL;
478 493
479 obj = next; 494 obj = next;
480 } 495 }
481 } 496 }
482 497
483 void 498 int
484 gdbpy_initialize_symtabs (void) 499 gdbpy_initialize_symtabs (void)
485 { 500 {
486 symtab_object_type.tp_new = PyType_GenericNew; 501 symtab_object_type.tp_new = PyType_GenericNew;
487 if (PyType_Ready (&symtab_object_type) < 0) 502 if (PyType_Ready (&symtab_object_type) < 0)
488 return; 503 return -1;
489 504
490 sal_object_type.tp_new = PyType_GenericNew; 505 sal_object_type.tp_new = PyType_GenericNew;
491 if (PyType_Ready (&sal_object_type) < 0) 506 if (PyType_Ready (&sal_object_type) < 0)
492 return; 507 return -1;
493 508
494 /* Register an objfile "free" callback so we can properly 509 /* Register an objfile "free" callback so we can properly
495 invalidate symbol tables, and symbol table and line data 510 invalidate symbol tables, and symbol table and line data
496 structures when an object file that is about to be 511 structures when an object file that is about to be
497 deleted. */ 512 deleted. */
498 stpy_objfile_data_key 513 stpy_objfile_data_key
499 = register_objfile_data_with_cleanup (NULL, del_objfile_symtab); 514 = register_objfile_data_with_cleanup (NULL, del_objfile_symtab);

error: old chunk mismatch

OLDNEW
« no previous file with comments | « gdb/python/py-symbol.c ('k') | gdb/python/py-threadevent.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698