1 This patch adds Python debugger support. It may be contributed upstream at |
|
2 some point, but the suitability (or lack thereof) has not yet been determined. |
|
3 |
|
4 --- Python-2.6.8/Makefile.pre.in.~4~ 2014-11-11 14:12:28.159605507 -0800 |
|
5 +++ Python-2.6.8/Makefile.pre.in 2014-11-11 14:12:28.295152443 -0800 |
|
6 @@ -355,7 +355,7 @@ |
|
7 |
|
8 # Default target |
|
9 all: build_all |
|
10 -build_all: $(BUILDPYTHON) oldsharedmods sharedmods |
|
11 +build_all: $(BUILDPYTHON) oldsharedmods sharedmods build-py_db |
|
12 |
|
13 # Compile a binary with gcc profile guided optimization. |
|
14 profile-opt: |
|
15 @@ -678,6 +678,16 @@ |
|
16 |
|
17 $(LIBRARY_OBJS) $(MODOBJS) Modules/python.o: $(PYTHON_HEADERS) |
|
18 |
|
19 +SHLIB_FLAGS = -shared -fpic -M $(srcdir)/py_db/mapfile-vers |
|
20 + |
|
21 +libpython2.6_db.so.1.0: $(srcdir)/py_db/libpython26_db.c |
|
22 + $(CC) -o $@ $(CFLAGS) $(CPPFLAGS) $(SHLIB_FLAGS) $< |
|
23 + |
|
24 +build-py_db: libpython2.6_db.so.1.0 |
|
25 + |
|
26 +install-py_db: libpython2.6_db.so.1.0 |
|
27 + $(INSTALL_SHARED) libpython2.6_db.so.1.0 $(DESTDIR)$(LIBDIR) |
|
28 + |
|
29 install-pycc: $(srcdir)/pycc |
|
30 $(INSTALL_SCRIPT) $< $(DESTDIR)$(BINLIBDEST) |
|
31 |
|
32 @@ -743,7 +753,7 @@ |
|
33 $(TESTPYTHON) $(TESTPROG) $(MEMTESTOPTS) |
|
34 |
|
35 # Install everything |
|
36 -install: @FRAMEWORKINSTALLFIRST@ altinstall bininstall maninstall @FRAMEWORKINSTALLLAST@ install-pycc |
|
37 +install: @FRAMEWORKINSTALLFIRST@ altinstall bininstall maninstall @FRAMEWORKINSTALLLAST@ install-py_db install-pycc |
|
38 |
|
39 # Install almost everything without disturbing previous versions |
|
40 altinstall: @FRAMEWORKALTINSTALLFIRST@ altbininstall libinstall inclinstall libainstall \ |
|
41 --- /dev/null |
|
42 +++ Python-2.6.4/py_db/libpython26_db.c |
|
43 @@ -0,0 +1,655 @@ |
|
44 +/* |
|
45 + * CDDL HEADER START |
|
46 + * |
|
47 + * The contents of this file are subject to the terms of the |
|
48 + * Common Development and Distribution License (the "License"). |
|
49 + * You may not use this file except in compliance with the License. |
|
50 + * |
|
51 + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
52 + * or http://www.opensolaris.org/os/licensing. |
|
53 + * See the License for the specific language governing permissions |
|
54 + * and limitations under the License. |
|
55 + * |
|
56 + * When distributing Covered Code, include this CDDL HEADER in each |
|
57 + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
58 + * If applicable, add the following below this CDDL HEADER, with the |
|
59 + * fields enclosed by brackets "[]" replaced with your own identifying |
|
60 + * information: Portions Copyright [yyyy] [name of copyright owner] |
|
61 + * |
|
62 + * CDDL HEADER END |
|
63 + */ |
|
64 +/* |
|
65 + * Copyright 2010 Sun Microsystems, Inc. All rights reserved. |
|
66 + * Use is subject to license terms. |
|
67 + */ |
|
68 + |
|
69 +#include <stdio.h> |
|
70 +#include <stdlib.h> |
|
71 +#include <string.h> |
|
72 +#include <errno.h> |
|
73 +#include <gelf.h> |
|
74 + |
|
75 +#include <Python.h> |
|
76 +#include <frameobject.h> |
|
77 + |
|
78 +#include "libpython26_db.h" |
|
79 +#if defined(_LP64) |
|
80 +#include "libpython26_db_32.h" |
|
81 +#endif /* _LP64 */ |
|
82 + |
|
83 +/* |
|
84 + * Because MDB always runs the debugger in the same datamodel as the target, |
|
85 + * only functions that are used by the procfs part of this interface (or shared |
|
86 + * between the two) are written as 64->32 aware. |
|
87 + */ |
|
88 +typedef struct pydb_arch_ops { |
|
89 + ssize_t (*strobj_readdata)(pydb_agent_t *, uintptr_t, unsigned char *, |
|
90 + size_t); |
|
91 + int (*frameinfo)(pydb_agent_t *, uintptr_t, char *, |
|
92 + size_t, char *, size_t, int *); |
|
93 +} pydb_arch_ops_t; |
|
94 + |
|
95 +struct pydb_agent { |
|
96 + struct ps_prochandle *pdb_ph; |
|
97 + int pdb_vers; |
|
98 + int pdb_is_64bit; |
|
99 + int pdb_datamodel; |
|
100 + const pydb_arch_ops_t *pdb_ops; |
|
101 +}; |
|
102 + |
|
103 +typedef uintptr_t (*pdi_next_cb_t)(pydb_iter_t *); |
|
104 + |
|
105 +struct pydb_iter { |
|
106 + struct ps_prochandle *pdi_ph; |
|
107 + uintptr_t pdi_current; |
|
108 + pdi_next_cb_t pdi_nextf; |
|
109 +}; |
|
110 + |
|
111 +#define LIBPYTHON "libpython2.6.so" |
|
112 + |
|
113 +#define MIN(x, y) (((x) < (y)) ? (x) : (y)) |
|
114 + |
|
115 +/* Generic interface to helper functions */ |
|
116 +static ssize_t pydb_strobj_readdata(pydb_agent_t *py, uintptr_t addr, |
|
117 + unsigned char *buf, size_t buf_len); |
|
118 +static int pydb_getlno(pydb_agent_t *py, uintptr_t lnotab_addr, int firstline, |
|
119 + int lastinst); |
|
120 +static int pydb_frameinfo(pydb_agent_t *py, uintptr_t addr, char *funcnm, |
|
121 + size_t funcnm_sz, char *filenm, size_t filenm_sz, int *lineno); |
|
122 + |
|
123 +/* datamodel specific implementation of helper functions */ |
|
124 +static ssize_t pydb_strobj_readdata_native(pydb_agent_t *py, uintptr_t addr, |
|
125 + unsigned char *buf, size_t buf_len); |
|
126 +static int pydb_frameinfo_native(pydb_agent_t *py, uintptr_t addr, char *funcnm, |
|
127 + size_t funcnm_sz, char *filenm, size_t filenm_sz, int *lineno); |
|
128 + |
|
129 +#if defined (_LP64) |
|
130 +static ssize_t pydb_strobj_readdata_32(pydb_agent_t *py, uintptr_t addr, |
|
131 + unsigned char *buf, size_t buf_len); |
|
132 +static int pydb_frameinfo_32(pydb_agent_t *py, uintptr_t addr, char *funcnm, |
|
133 + size_t funcnm_sz, char *filenm, size_t filenm_sz, int *lineno); |
|
134 +#endif /* _LP64 */ |
|
135 + |
|
136 +static ssize_t pydb_strobj_readstr(pydb_agent_t *py, uintptr_t addr, char *buf, |
|
137 + size_t len); |
|
138 + |
|
139 +/* Iterator function next routines. Plugable, configured by iterator init */ |
|
140 +static uintptr_t pydb_frame_iter_next(pydb_iter_t *iter); |
|
141 +static uintptr_t pydb_interp_iter_next(pydb_iter_t *iter); |
|
142 +static uintptr_t pydb_thread_iter_next(pydb_iter_t *iter); |
|
143 + |
|
144 +static const char *strbasename(const char *s); |
|
145 + |
|
146 +static const pydb_arch_ops_t arch_ops_native = { |
|
147 + .frameinfo = pydb_frameinfo_native, |
|
148 + .strobj_readdata = pydb_strobj_readdata_native, |
|
149 +}; |
|
150 + |
|
151 +#if defined (_LP64) |
|
152 +static const pydb_arch_ops_t arch_ops_32 = { |
|
153 + .frameinfo = pydb_frameinfo_32, |
|
154 + .strobj_readdata = pydb_strobj_readdata_32, |
|
155 +}; |
|
156 +#endif /* _LP64 */ |
|
157 + |
|
158 +static const char * |
|
159 +strbasename(const char *s) |
|
160 +{ |
|
161 + const char *p = strrchr(s, '/'); |
|
162 + |
|
163 + if (p == NULL) |
|
164 + return (s); |
|
165 + |
|
166 + return (++p); |
|
167 +} |
|
168 + |
|
169 +/* Agent creation / destruction routines */ |
|
170 + |
|
171 +pydb_agent_t * |
|
172 +pydb_agent_create(struct ps_prochandle *P, int vers) |
|
173 +{ |
|
174 + pydb_agent_t *py; |
|
175 + int datamodel; |
|
176 + |
|
177 + if (vers != PYDB_VERSION) { |
|
178 + errno = ENOTSUP; |
|
179 + return (NULL); |
|
180 + } |
|
181 + |
|
182 + if (ps_pdmodel(P, &datamodel) != PS_OK) { |
|
183 + return (NULL); |
|
184 + } |
|
185 + |
|
186 + py = (pydb_agent_t *)malloc(sizeof (pydb_agent_t)); |
|
187 + if (py == NULL) { |
|
188 + return (NULL); |
|
189 + } |
|
190 + |
|
191 + py->pdb_ph = P; |
|
192 + py->pdb_vers = vers; |
|
193 + py->pdb_datamodel = datamodel; |
|
194 + py->pdb_is_64bit = 0; |
|
195 + py->pdb_ops = &arch_ops_native; |
|
196 + |
|
197 +#if defined (_LP64) |
|
198 + py->pdb_is_64bit = (datamodel == PR_MODEL_LP64); |
|
199 + if (!py->pdb_is_64bit) { |
|
200 + py->pdb_ops = &arch_ops_32; |
|
201 + } |
|
202 +#endif /* _LP64 */ |
|
203 + |
|
204 + return (py); |
|
205 +} |
|
206 + |
|
207 +void |
|
208 +pydb_agent_destroy(pydb_agent_t *py) |
|
209 +{ |
|
210 + if (py == NULL) { |
|
211 + return; |
|
212 + } |
|
213 + |
|
214 + free(py); |
|
215 +} |
|
216 + |
|
217 +/* Helper functions */ |
|
218 +static int |
|
219 +pydb_getlno(pydb_agent_t *py, uintptr_t lnotab_addr, int firstline, |
|
220 + int lastinst) |
|
221 +{ |
|
222 + unsigned char lnotab[4096]; |
|
223 + ssize_t lnotab_len; |
|
224 + int addr, line; |
|
225 + int i; |
|
226 + |
|
227 + lnotab_len = pydb_strobj_readdata(py, lnotab_addr, lnotab, |
|
228 + sizeof (lnotab)); |
|
229 + if (lnotab_len < 0) { |
|
230 + return (-1); |
|
231 + } |
|
232 + |
|
233 + /* |
|
234 + * Python's line number algorithm is arcane. See here for details: |
|
235 + * http://svn.python.org/projects/python/trunk/Objects/lnotab_notes.txt |
|
236 + */ |
|
237 + |
|
238 + line = firstline; |
|
239 + for (addr = i = 0; i < lnotab_len; i += 2) { |
|
240 + if (addr + lnotab[i] > lastinst) { |
|
241 + break; |
|
242 + } |
|
243 + addr += lnotab[i]; |
|
244 + line += lnotab[i + 1]; |
|
245 + } |
|
246 + |
|
247 + return (line); |
|
248 +} |
|
249 + |
|
250 +static ssize_t |
|
251 +pydb_strobj_readdata(pydb_agent_t *py, uintptr_t addr, unsigned char *buf, |
|
252 + size_t buf_len) |
|
253 +{ |
|
254 + return (py->pdb_ops->strobj_readdata(py, addr, buf, buf_len)); |
|
255 +} |
|
256 + |
|
257 +static ssize_t |
|
258 +pydb_strobj_readdata_native(pydb_agent_t *py, uintptr_t addr, |
|
259 + unsigned char *buf, size_t buf_len) |
|
260 +{ |
|
261 + PyStringObject sobj; |
|
262 + ssize_t obj_sz; |
|
263 + ssize_t read_sz; |
|
264 + psaddr_t straddr; |
|
265 + |
|
266 + /* |
|
267 + * PyStringObjects are variable size. The size of the PyStringObject |
|
268 + * struct is fixed, and known at compile time; however, the size of the |
|
269 + * associated buffer is variable. The char[1] element at the end of the |
|
270 + * structure contains the string, and the ob_size of the PyStringObject |
|
271 + * indicates how much extra space was allocated to contain the string |
|
272 + * buffer at the object's tail. Read in the fixed size portion of the |
|
273 + * object first, and then read the contents of the data buffer into the |
|
274 + * buffer passed by the caller. |
|
275 + */ |
|
276 + |
|
277 + if (ps_pread(py->pdb_ph, addr, &sobj, sizeof (PyStringObject)) |
|
278 + != PS_OK) { |
|
279 + return (-1); |
|
280 + } |
|
281 + |
|
282 + obj_sz = (ssize_t)PyString_GET_SIZE(&sobj); |
|
283 + |
|
284 + read_sz = MIN(obj_sz, (ssize_t)buf_len); |
|
285 + straddr = (psaddr_t)(addr + offsetof(PyStringObject, ob_sval)); |
|
286 + |
|
287 + if (ps_pread(py->pdb_ph, straddr, buf, (size_t)read_sz) != PS_OK) { |
|
288 + return (-1); |
|
289 + } |
|
290 + |
|
291 + return (read_sz); |
|
292 +} |
|
293 + |
|
294 +#if defined(_LP64) |
|
295 +static ssize_t |
|
296 +pydb_strobj_readdata_32(pydb_agent_t *py, uintptr_t addr, |
|
297 + unsigned char *buf, size_t buf_len) |
|
298 +{ |
|
299 + PyStringObject32 sobj; |
|
300 + ssize_t obj_sz; |
|
301 + ssize_t read_sz; |
|
302 + psaddr_t straddr; |
|
303 + |
|
304 + /* |
|
305 + * PyStringObjects are variable size. The size of the PyStringObject |
|
306 + * struct is fixed, and known at compile time; however, the size of the |
|
307 + * associated buffer is variable. The char[1] element at the end of the |
|
308 + * structure contains the string, and the ob_size of the PyStringObject |
|
309 + * indicates how much extra space was allocated to contain the string |
|
310 + * buffer at the object's tail. Read in the fixed size portion of the |
|
311 + * object first, and then read the contents of the data buffer into the |
|
312 + * buffer passed by the caller. |
|
313 + */ |
|
314 + |
|
315 + if (ps_pread(py->pdb_ph, addr, &sobj, sizeof (PyStringObject32)) |
|
316 + != PS_OK) { |
|
317 + return (-1); |
|
318 + } |
|
319 + |
|
320 + obj_sz = (ssize_t)PyString_GET_SIZE32(&sobj); |
|
321 + |
|
322 + read_sz = MIN(obj_sz, (ssize_t)buf_len); |
|
323 + straddr = (psaddr_t)(addr + offsetof(PyStringObject32, ob_sval)); |
|
324 + |
|
325 + if (ps_pread(py->pdb_ph, straddr, buf, (size_t)read_sz) != PS_OK) { |
|
326 + return (-1); |
|
327 + } |
|
328 + |
|
329 + return (read_sz); |
|
330 +} |
|
331 +#endif /* _LP64 */ |
|
332 + |
|
333 +/* |
|
334 + * Most Python PyStringObjects contain strings, as one would expect. However, |
|
335 + * due to some sleazy hackery in parts of the Python code, some string objects |
|
336 + * are used as buffers for binary data. In the general case, |
|
337 + * pydb_strobj_readstr() should be used to read strings out of string objects. |
|
338 + * It wraps pydb_strobj_readdata(), which should be used by callers only when |
|
339 + * trying to retrieve binary data. (This routine does some string cleanup). |
|
340 + */ |
|
341 +static ssize_t |
|
342 +pydb_strobj_readstr(pydb_agent_t *py, uintptr_t addr, char *buf, |
|
343 + size_t buf_len) |
|
344 +{ |
|
345 + ssize_t read_sz; |
|
346 + |
|
347 + read_sz = pydb_strobj_readdata(py, addr, (unsigned char *)buf, buf_len); |
|
348 + |
|
349 + if (read_sz >= 0) { |
|
350 + if (read_sz >= buf_len) { |
|
351 + read_sz = buf_len - 1; |
|
352 + } |
|
353 + |
|
354 + buf[read_sz] = '\0'; |
|
355 + } |
|
356 + |
|
357 + return (read_sz); |
|
358 +} |
|
359 + |
|
360 + |
|
361 +static int |
|
362 +pydb_frameinfo(pydb_agent_t *py, uintptr_t addr, char *funcnm, |
|
363 + size_t funcnm_sz, char *filenm, size_t filenm_sz, int *lineno) |
|
364 +{ |
|
365 + return (py->pdb_ops->frameinfo(py, addr, funcnm, funcnm_sz, |
|
366 + filenm, filenm_sz, lineno)); |
|
367 +} |
|
368 + |
|
369 +static int |
|
370 +pydb_frameinfo_native(pydb_agent_t *py, uintptr_t addr, char *funcnm, |
|
371 + size_t funcnm_sz, char *filenm, size_t filenm_sz, int *lineno) |
|
372 +{ |
|
373 + PyFrameObject fo; |
|
374 + PyCodeObject co; |
|
375 + ssize_t rc; |
|
376 + |
|
377 + if (ps_pread(py->pdb_ph, addr, &fo, sizeof (PyFrameObject)) |
|
378 + != PS_OK) { |
|
379 + return (-1); |
|
380 + } |
|
381 + |
|
382 + if (ps_pread(py->pdb_ph, (uintptr_t)fo.f_code, &co, |
|
383 + sizeof (PyCodeObject)) != PS_OK) { |
|
384 + return (-1); |
|
385 + } |
|
386 + |
|
387 + rc = pydb_strobj_readstr(py, (uintptr_t)co.co_name, funcnm, funcnm_sz); |
|
388 + if (rc < 0) { |
|
389 + return (-1); |
|
390 + } |
|
391 + |
|
392 + rc = pydb_strobj_readstr(py, (uintptr_t)co.co_filename, filenm, |
|
393 + filenm_sz); |
|
394 + if (rc < 0) { |
|
395 + return (-1); |
|
396 + } |
|
397 + |
|
398 + *lineno = pydb_getlno(py, (uintptr_t)co.co_lnotab, co.co_firstlineno, |
|
399 + fo.f_lasti); |
|
400 + if (*lineno < 0) { |
|
401 + return (-1); |
|
402 + } |
|
403 + |
|
404 + return (0); |
|
405 +} |
|
406 + |
|
407 +#if defined (_LP64) |
|
408 +static int |
|
409 +pydb_frameinfo_32(pydb_agent_t *py, uintptr_t addr, char *funcnm, |
|
410 + size_t funcnm_sz, char *filenm, size_t filenm_sz, int *lineno) |
|
411 +{ |
|
412 + PyFrameObject32 fo; |
|
413 + PyCodeObject32 co; |
|
414 + ssize_t rc; |
|
415 + |
|
416 + if (ps_pread(py->pdb_ph, addr, &fo, sizeof (PyFrameObject32)) |
|
417 + != PS_OK) { |
|
418 + return (-1); |
|
419 + } |
|
420 + |
|
421 + if (ps_pread(py->pdb_ph, (uintptr_t)fo.f_code, &co, |
|
422 + sizeof (PyCodeObject32)) != PS_OK) { |
|
423 + return (-1); |
|
424 + } |
|
425 + |
|
426 + rc = pydb_strobj_readstr(py, (uintptr_t)co.co_name, funcnm, funcnm_sz); |
|
427 + if (rc < 0) { |
|
428 + return (-1); |
|
429 + } |
|
430 + |
|
431 + rc = pydb_strobj_readstr(py, (uintptr_t)co.co_filename, filenm, |
|
432 + filenm_sz); |
|
433 + if (rc < 0) { |
|
434 + return (-1); |
|
435 + } |
|
436 + |
|
437 + *lineno = pydb_getlno(py, (uintptr_t)co.co_lnotab, co.co_firstlineno, |
|
438 + fo.f_lasti); |
|
439 + if (*lineno < 0) { |
|
440 + return (-1); |
|
441 + } |
|
442 + |
|
443 + return (0); |
|
444 +} |
|
445 + |
|
446 +#endif /* _LP64 */ |
|
447 + |
|
448 +/* Functions that are part of the library's interface */ |
|
449 + |
|
450 +/* |
|
451 + * Given the address of a PyFrameObject, and a buffer of a known size, |
|
452 + * fill the buffer with a description of the frame. |
|
453 + */ |
|
454 +int |
|
455 +pydb_get_frameinfo(pydb_agent_t *py, uintptr_t frame_addr, char *fbuf, |
|
456 + size_t bufsz, int verbose) |
|
457 +{ |
|
458 + char funcname[1024]; |
|
459 + char filename[1024]; |
|
460 + char *fn; |
|
461 + int lineno; |
|
462 + int length = (py->pdb_is_64bit ? 16 : 8); |
|
463 + int rc; |
|
464 + |
|
465 + rc = pydb_frameinfo(py, frame_addr, funcname, sizeof (funcname), |
|
466 + filename, sizeof (filename), &lineno); |
|
467 + if (rc < 0) { |
|
468 + return (-1); |
|
469 + } |
|
470 + |
|
471 + if (!verbose) { |
|
472 + fn = (char *)strbasename(filename); |
|
473 + } else { |
|
474 + fn = filename; |
|
475 + } |
|
476 + |
|
477 + (void) snprintf(fbuf, bufsz, "%0.*lx %s:%d %s()\n", length, |
|
478 + frame_addr, fn, lineno, funcname); |
|
479 + |
|
480 + return (0); |
|
481 +} |
|
482 + |
|
483 +/* |
|
484 + * Return a description about a PyFrameObject, if the object is |
|
485 + * actually a PyFrameObject. In this case, the pc argument is checked |
|
486 + * to make sure that it came from a function that takes a PyFrameObject |
|
487 + * as its first (argv[0]) argument. |
|
488 + */ |
|
489 +int |
|
490 +pydb_pc_frameinfo(pydb_agent_t *py, uintptr_t pc, uintptr_t frame_addr, |
|
491 + char *fbuf, size_t bufsz) |
|
492 +{ |
|
493 + char funcname[1024]; |
|
494 + char filename[1024]; |
|
495 + int lineno; |
|
496 + int rc; |
|
497 + ps_sym_t psym; |
|
498 + |
|
499 + /* |
|
500 + * If PC doesn't match PyEval_EvalFrameEx in either libpython |
|
501 + * or the executable, don't decode it. |
|
502 + */ |
|
503 + if (ps_pglobal_sym(py->pdb_ph, LIBPYTHON, "PyEval_EvalFrameEx", &psym) |
|
504 + != PS_OK) { |
|
505 + return (-1); |
|
506 + } |
|
507 + |
|
508 + /* If symbol found, ensure that PC falls within PyEval_EvalFrameEx. */ |
|
509 + if (pc < psym.st_value || pc > psym.st_value + psym.st_size) { |
|
510 + return (-1); |
|
511 + } |
|
512 + |
|
513 + rc = pydb_frameinfo(py, frame_addr, funcname, sizeof (funcname), |
|
514 + filename, sizeof (filename), &lineno); |
|
515 + if (rc < 0) { |
|
516 + return (-1); |
|
517 + } |
|
518 + |
|
519 + (void) snprintf(fbuf, bufsz, "[ %s:%d (%s) ]\n", filename, lineno, |
|
520 + funcname); |
|
521 + |
|
522 + return (0); |
|
523 +} |
|
524 + |
|
525 +/* |
|
526 + * Walks the list of PyInterpreterState objects. If caller doesn't |
|
527 + * supply address of list, this method will look it up. |
|
528 + */ |
|
529 +pydb_iter_t * |
|
530 +pydb_interp_iter_init(pydb_agent_t *py, uintptr_t addr) |
|
531 +{ |
|
532 + pydb_iter_t *itr; |
|
533 + uintptr_t i_addr; |
|
534 + int rc; |
|
535 + |
|
536 + if (addr == 0) { |
|
537 + rc = ps_pglobal_lookup(py->pdb_ph, LIBPYTHON, "interp_head", |
|
538 + (psaddr_t *)&addr); |
|
539 + if (rc != PS_OK) { |
|
540 + return (NULL); |
|
541 + } |
|
542 + } |
|
543 + |
|
544 + if (ps_pread(py->pdb_ph, (uintptr_t)addr, &i_addr, sizeof (uintptr_t)) |
|
545 + != PS_OK) { |
|
546 + return (NULL); |
|
547 + } |
|
548 + |
|
549 + itr = malloc(sizeof (pydb_iter_t)); |
|
550 + if (itr == NULL) { |
|
551 + return (NULL); |
|
552 + } |
|
553 + |
|
554 + itr->pdi_ph = py->pdb_ph; |
|
555 + itr->pdi_current = i_addr; |
|
556 + itr->pdi_nextf = pydb_interp_iter_next; |
|
557 + |
|
558 + return (itr); |
|
559 +} |
|
560 + |
|
561 +static uintptr_t |
|
562 +pydb_interp_iter_next(pydb_iter_t *iter) |
|
563 +{ |
|
564 + PyInterpreterState st; |
|
565 + uintptr_t cur; |
|
566 + |
|
567 + cur = iter->pdi_current; |
|
568 + |
|
569 + if (cur == 0) { |
|
570 + return (cur); |
|
571 + } |
|
572 + |
|
573 + if (ps_pread(iter->pdi_ph, cur, &st, sizeof (PyInterpreterState)) |
|
574 + != PS_OK) { |
|
575 + iter->pdi_current = 0; |
|
576 + return (0); |
|
577 + } |
|
578 + |
|
579 + iter->pdi_current = (uintptr_t)st.next; |
|
580 + |
|
581 + return (cur); |
|
582 +} |
|
583 + |
|
584 +/* |
|
585 + * Walk a list of Python PyFrameObjects. The addr argument must be |
|
586 + * the address of a valid PyThreadState object. |
|
587 + */ |
|
588 +pydb_iter_t * |
|
589 +pydb_frame_iter_init(pydb_agent_t *py, uintptr_t addr) |
|
590 +{ |
|
591 + pydb_iter_t *itr; |
|
592 + PyThreadState ts; |
|
593 + |
|
594 + if (ps_pread(py->pdb_ph, (uintptr_t)addr, &ts, sizeof (PyThreadState)) |
|
595 + != PS_OK) { |
|
596 + return (NULL); |
|
597 + } |
|
598 + |
|
599 + itr = malloc(sizeof (pydb_iter_t)); |
|
600 + if (itr == NULL) { |
|
601 + return (NULL); |
|
602 + } |
|
603 + |
|
604 + itr->pdi_ph = py->pdb_ph; |
|
605 + itr->pdi_current = (uintptr_t)ts.frame; |
|
606 + itr->pdi_nextf = pydb_frame_iter_next; |
|
607 + |
|
608 + return (itr); |
|
609 +} |
|
610 + |
|
611 +static uintptr_t |
|
612 +pydb_frame_iter_next(pydb_iter_t *iter) |
|
613 +{ |
|
614 + PyFrameObject fo; |
|
615 + uintptr_t cur; |
|
616 + |
|
617 + cur = iter->pdi_current; |
|
618 + |
|
619 + if (cur == 0) { |
|
620 + return (cur); |
|
621 + } |
|
622 + |
|
623 + if (ps_pread(iter->pdi_ph, cur, &fo, sizeof (PyFrameObject)) |
|
624 + != PS_OK) { |
|
625 + iter->pdi_current = 0; |
|
626 + return (0); |
|
627 + } |
|
628 + |
|
629 + iter->pdi_current = (uintptr_t)fo.f_back; |
|
630 + |
|
631 + return (cur); |
|
632 +} |
|
633 + |
|
634 +/* |
|
635 + * Walk a list of Python PyThreadState objects. The addr argument must be |
|
636 + * the address of a valid PyInterpreterState object. |
|
637 + */ |
|
638 +pydb_iter_t * |
|
639 +pydb_thread_iter_init(pydb_agent_t *py, uintptr_t addr) |
|
640 +{ |
|
641 + pydb_iter_t *itr; |
|
642 + PyInterpreterState is; |
|
643 + |
|
644 + if (ps_pread(py->pdb_ph, (uintptr_t)addr, &is, |
|
645 + sizeof (PyInterpreterState)) != PS_OK) { |
|
646 + return (NULL); |
|
647 + } |
|
648 + |
|
649 + itr = malloc(sizeof (pydb_iter_t)); |
|
650 + if (itr == NULL) { |
|
651 + return (NULL); |
|
652 + } |
|
653 + |
|
654 + itr->pdi_ph = py->pdb_ph; |
|
655 + itr->pdi_current = (uintptr_t)is.tstate_head; |
|
656 + itr->pdi_nextf = pydb_thread_iter_next; |
|
657 + |
|
658 + return (itr); |
|
659 +} |
|
660 + |
|
661 +static uintptr_t |
|
662 +pydb_thread_iter_next(pydb_iter_t *iter) |
|
663 +{ |
|
664 + PyThreadState ts; |
|
665 + uintptr_t cur; |
|
666 + |
|
667 + cur = iter->pdi_current; |
|
668 + |
|
669 + if (cur == 0) { |
|
670 + return (cur); |
|
671 + } |
|
672 + |
|
673 + if (ps_pread(iter->pdi_ph, cur, &ts, sizeof (PyThreadState)) != PS_OK) { |
|
674 + iter->pdi_current = 0; |
|
675 + return (0); |
|
676 + } |
|
677 + |
|
678 + iter->pdi_current = (uintptr_t)ts.next; |
|
679 + |
|
680 + return (cur); |
|
681 +} |
|
682 + |
|
683 + |
|
684 +uintptr_t |
|
685 +pydb_iter_next(pydb_iter_t *iter) |
|
686 +{ |
|
687 + return (iter->pdi_nextf(iter)); |
|
688 +} |
|
689 + |
|
690 +void |
|
691 +pydb_iter_fini(pydb_iter_t *iter) |
|
692 +{ |
|
693 + if (iter == NULL) { |
|
694 + return; |
|
695 + } |
|
696 + |
|
697 + free(iter); |
|
698 +} |
|
699 diff --git Python-2.6.4/py_db/libpython26_db.h Python-2.6.4/py_db/libpython26_db.h |
|
700 new file mode 100644 |
|
701 --- /dev/null |
|
702 +++ Python-2.6.4/py_db/libpython26_db.h |
|
703 @@ -0,0 +1,74 @@ |
|
704 +/* |
|
705 + * CDDL HEADER START |
|
706 + * |
|
707 + * The contents of this file are subject to the terms of the |
|
708 + * Common Development and Distribution License (the "License"). |
|
709 + * You may not use this file except in compliance with the License. |
|
710 + * |
|
711 + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
712 + * or http://www.opensolaris.org/os/licensing. |
|
713 + * See the License for the specific language governing permissions |
|
714 + * and limitations under the License. |
|
715 + * |
|
716 + * When distributing Covered Code, include this CDDL HEADER in each |
|
717 + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
718 + * If applicable, add the following below this CDDL HEADER, with the |
|
719 + * fields enclosed by brackets "[]" replaced with your own identifying |
|
720 + * information: Portions Copyright [yyyy] [name of copyright owner] |
|
721 + * |
|
722 + * CDDL HEADER END |
|
723 + */ |
|
724 +/* |
|
725 + * Copyright 2010 Sun Microsystems, Inc. All rights reserved. |
|
726 + * Use is subject to license terms. |
|
727 + */ |
|
728 + |
|
729 +#ifndef _LIBPYTHON26_DB_H |
|
730 +#define _LIBPYTHON26_DB_H |
|
731 + |
|
732 +#include <proc_service.h> |
|
733 + |
|
734 +#ifdef __cplusplus |
|
735 +extern "C" { |
|
736 +#endif |
|
737 + |
|
738 +/* Agent is opaque to library's consumers. */ |
|
739 +typedef struct pydb_agent pydb_agent_t; |
|
740 + |
|
741 +/* |
|
742 + * Library's debug version is 1. Changes to interface should increase this |
|
743 + * number. |
|
744 + */ |
|
745 +#define PYDB_VERSION 1 |
|
746 + |
|
747 +/* Agent creation/destruction routines */ |
|
748 +extern pydb_agent_t *pydb_agent_create(struct ps_prochandle *P, int vers); |
|
749 +extern void pydb_agent_destroy(pydb_agent_t *py); |
|
750 + |
|
751 +/* Used by callers that know they are looking at a PyFrameObject */ |
|
752 +extern int pydb_get_frameinfo(pydb_agent_t *py, uintptr_t frame_addr, |
|
753 + char *fbuf, size_t bufsz, int verbose); |
|
754 + |
|
755 +/* |
|
756 + * Used by callers that don't know if they're looking at PyFrameObject. |
|
757 + * Checks PC for traceable functions. |
|
758 + */ |
|
759 +extern int pydb_pc_frameinfo(pydb_agent_t *py, uintptr_t pc, |
|
760 + uintptr_t frame_addr, char *fbuf, size_t bufsz); |
|
761 + |
|
762 +/* Iterator functions */ |
|
763 +typedef struct pydb_iter pydb_iter_t; |
|
764 + |
|
765 +extern pydb_iter_t *pydb_frame_iter_init(pydb_agent_t *py, uintptr_t addr); |
|
766 +extern pydb_iter_t *pydb_interp_iter_init(pydb_agent_t *py, |
|
767 + uintptr_t addr); |
|
768 +extern pydb_iter_t *pydb_thread_iter_init(pydb_agent_t *py, |
|
769 + uintptr_t addr); |
|
770 +extern void pydb_iter_fini(pydb_iter_t *iter); |
|
771 +extern uintptr_t pydb_iter_next(pydb_iter_t *iter); |
|
772 + |
|
773 +#ifdef __cplusplus |
|
774 +} |
|
775 +#endif |
|
776 + |
|
777 +#endif /* _LIBPYTHON26_DB_H */ |
|
778 diff --git Python-2.6.4/py_db/libpython26_db_32.h Python-2.6.4/py_db/libpython26_db_32.h |
|
779 new file mode 100644 |
|
780 --- /dev/null |
|
781 +++ Python-2.6.4/py_db/libpython26_db_32.h |
|
782 @@ -0,0 +1,122 @@ |
|
783 +/* |
|
784 + * CDDL HEADER START |
|
785 + * |
|
786 + * The contents of this file are subject to the terms of the |
|
787 + * Common Development and Distribution License (the "License"). |
|
788 + * You may not use this file except in compliance with the License. |
|
789 + * |
|
790 + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
791 + * or http://www.opensolaris.org/os/licensing. |
|
792 + * See the License for the specific language governing permissions |
|
793 + * and limitations under the License. |
|
794 + * |
|
795 + * When distributing Covered Code, include this CDDL HEADER in each |
|
796 + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
797 + * If applicable, add the following below this CDDL HEADER, with the |
|
798 + * fields enclosed by brackets "[]" replaced with your own identifying |
|
799 + * information: Portions Copyright [yyyy] [name of copyright owner] |
|
800 + * |
|
801 + * CDDL HEADER END |
|
802 + */ |
|
803 +/* |
|
804 + * Copyright 2010 Sun Microsystems, Inc. All rights reserved. |
|
805 + * Use is subject to license terms. |
|
806 + */ |
|
807 + |
|
808 +#ifndef _LIBPYTHON26_DB_32_H |
|
809 +#define _LIBPYTHON26_DB_32_H |
|
810 + |
|
811 +#ifdef __cplusplus |
|
812 +extern "C" { |
|
813 +#endif |
|
814 + |
|
815 +#include <sys/types.h> |
|
816 + |
|
817 +/* |
|
818 + * Define 32-bit Python data structures for use by the 64-bit debugger. This |
|
819 + * is so that a 64-bit debugger may properly examine a 32-bit process. |
|
820 + * |
|
821 + * In many cases, the debug library is only concerned with a few fields in the |
|
822 + * Python structure. In that case, the other ancillary fields are elided. |
|
823 + */ |
|
824 + |
|
825 +typedef uint32_t uintptr32_t; |
|
826 +typedef int32_t Py_ssize32_t; |
|
827 + |
|
828 +typedef struct _is32 { |
|
829 + uintptr32_t next; |
|
830 + uintptr32_t tstate_head; |
|
831 +} PyInterpreterState32; |
|
832 + |
|
833 +typedef struct _ts32 { |
|
834 + uintptr32_t next; |
|
835 + uintptr32_t interp; |
|
836 + uintptr32_t frame; |
|
837 +} PyThreadState32; |
|
838 + |
|
839 +#define PyObject_HEAD32 \ |
|
840 + Py_ssize32_t ob_refcnt; \ |
|
841 + uintptr32_t ob_type; |
|
842 + |
|
843 +#define PyObject_VAR_HEAD32 \ |
|
844 + PyObject_HEAD32 \ |
|
845 + Py_ssize32_t ob_size; |
|
846 + |
|
847 +typedef struct { |
|
848 + PyObject_HEAD32 |
|
849 +} PyObject32; |
|
850 + |
|
851 +typedef struct { |
|
852 + PyObject_VAR_HEAD32 |
|
853 +} PyVarObject32; |
|
854 + |
|
855 +typedef struct { |
|
856 + PyObject_VAR_HEAD32 |
|
857 + int32_t ob_shash; |
|
858 + int ob_sstate; |
|
859 + char ob_sval[1]; |
|
860 +} PyStringObject32; |
|
861 + |
|
862 +#define Py_SIZE32(ob) (((PyVarObject32*)(ob))->ob_size) |
|
863 +#define PyString_GET_SIZE32(op) Py_SIZE32(op) |
|
864 +#define PyString_AS_STRING32(op) (((PyStringObject32 *)(op))->ob_sval) |
|
865 + |
|
866 +typedef struct { |
|
867 + PyObject_VAR_HEAD32 |
|
868 + uintptr32_t f_back; |
|
869 + uintptr32_t f_code; |
|
870 + uintptr32_t f_builtins; |
|
871 + uintptr32_t f_globals; |
|
872 + uintptr32_t f_locals; |
|
873 + uintptr32_t f_valuestack; |
|
874 + uintptr32_t f_stacktop; |
|
875 + uintptr32_t f_trace; |
|
876 + uintptr32_t f_exc_typpe, f_exc_value, f_exc_traceback; |
|
877 + uintptr32_t f_tstate; |
|
878 + int f_lasti; |
|
879 + int f_lineno; |
|
880 +} PyFrameObject32; |
|
881 + |
|
882 +typedef struct { |
|
883 + PyObject_HEAD32 |
|
884 + int co_argcount; |
|
885 + int co_nlocals; |
|
886 + int co_stacksize; |
|
887 + int co_flags; |
|
888 + uintptr32_t co_code; |
|
889 + uintptr32_t co_consts; |
|
890 + uintptr32_t co_names; |
|
891 + uintptr32_t co_varnames; |
|
892 + uintptr32_t co_freevars; |
|
893 + uintptr32_t co_cellvars; |
|
894 + uintptr32_t co_filename; |
|
895 + uintptr32_t co_name; |
|
896 + int co_firstlineno; |
|
897 + uintptr32_t co_lnotab; |
|
898 +} PyCodeObject32; |
|
899 + |
|
900 +#ifdef __cplusplus |
|
901 +} |
|
902 +#endif |
|
903 + |
|
904 +#endif /* _LIBPYTHON26_DB_32_H */ |
|
905 diff --git Python-2.6.4/py_db/mapfile-vers Python-2.6.4/py_db/mapfile-vers |
|
906 new file mode 100644 |
|
907 --- /dev/null |
|
908 +++ Python-2.6.4/py_db/mapfile-vers |
|
909 @@ -0,0 +1,40 @@ |
|
910 +# |
|
911 +# CDDL HEADER START |
|
912 +# |
|
913 +# The contents of this file are subject to the terms of the |
|
914 +# Common Development and Distribution License (the "License"). |
|
915 +# You may not use this file except in compliance with the License. |
|
916 +# |
|
917 +# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
918 +# or http://www.opensolaris.org/os/licensing. |
|
919 +# See the License for the specific language governing permissions |
|
920 +# and limitations under the License. |
|
921 +# |
|
922 +# When distributing Covered Code, include this CDDL HEADER in each |
|
923 +# file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
924 +# If applicable, add the following below this CDDL HEADER, with the |
|
925 +# fields enclosed by brackets "[]" replaced with your own identifying |
|
926 +# information: Portions Copyright [yyyy] [name of copyright owner] |
|
927 +# |
|
928 +# CDDL HEADER END |
|
929 +# |
|
930 + |
|
931 +# |
|
932 +# Copyright 2010 Sun Microsystems, Inc. All rights reserved. |
|
933 +# Use is subject to license terms. |
|
934 +# |
|
935 + |
|
936 +SUNWprivate_1.1 { |
|
937 + global: |
|
938 + pydb_agent_create; |
|
939 + pydb_agent_destroy; |
|
940 + pydb_frame_iter_init; |
|
941 + pydb_get_frameinfo; |
|
942 + pydb_pc_frameinfo; |
|
943 + pydb_interp_iter_init; |
|
944 + pydb_thread_iter_init; |
|
945 + pydb_iter_fini; |
|
946 + pydb_iter_next; |
|
947 + local: |
|
948 + *; |
|
949 +}; |
|