35 -install: @FRAMEWORKINSTALLFIRST@ commoninstall bininstall maninstall @FRAMEWORKINSTALLLAST@ |
35 -install: @FRAMEWORKINSTALLFIRST@ commoninstall bininstall maninstall @FRAMEWORKINSTALLLAST@ |
36 +install: @FRAMEWORKINSTALLFIRST@ commoninstall bininstall maninstall install-py_db @FRAMEWORKINSTALLLAST@ |
36 +install: @FRAMEWORKINSTALLFIRST@ commoninstall bininstall maninstall install-py_db @FRAMEWORKINSTALLLAST@ |
37 if test "x$(ENSUREPIP)" != "xno" ; then \ |
37 if test "x$(ENSUREPIP)" != "xno" ; then \ |
38 case $(ENSUREPIP) in \ |
38 case $(ENSUREPIP) in \ |
39 upgrade) ensurepip="--upgrade" ;; \ |
39 upgrade) ensurepip="--upgrade" ;; \ |
40 --- /dev/null |
40 --- /dev/null 2015-05-14 14:46:26.000000000 -0700 |
41 +++ Python-3.4.0/py_db/libpython34_db.c |
41 +++ Python-3.4.3/py_db/libpython34_db.c 2015-05-14 14:45:15.723529281 -0700 |
42 @@ -0,0 +1,654 @@ |
42 @@ -0,0 +1,583 @@ |
43 +/* |
43 +/* |
44 + * CDDL HEADER START |
44 + * CDDL HEADER START |
45 + * |
45 + * |
46 + * The contents of this file are subject to the terms of the |
46 + * The contents of this file are subject to the terms of the |
47 + * Common Development and Distribution License (the "License"). |
47 + * Common Development and Distribution License (the "License"). |
72 + |
72 + |
73 +#include <Python.h> |
73 +#include <Python.h> |
74 +#include <frameobject.h> |
74 +#include <frameobject.h> |
75 + |
75 + |
76 +#include "libpython34_db.h" |
76 +#include "libpython34_db.h" |
77 +#if defined(_LP64) |
|
78 +#include "libpython34_db_32.h" |
|
79 +#endif /* _LP64 */ |
|
80 + |
|
81 +/* |
|
82 + * Because MDB always runs the debugger in the same datamodel as the target, |
|
83 + * only functions that are used by the procfs part of this interface (or shared |
|
84 + * between the two) are written as 64->32 aware. |
|
85 + */ |
|
86 +typedef struct pydb_arch_ops { |
|
87 + ssize_t (*strobj_readdata)(pydb_agent_t *, uintptr_t, unsigned char *, |
|
88 + size_t); |
|
89 + int (*frameinfo)(pydb_agent_t *, uintptr_t, char *, |
|
90 + size_t, char *, size_t, int *); |
|
91 +} pydb_arch_ops_t; |
|
92 + |
77 + |
93 +struct pydb_agent { |
78 +struct pydb_agent { |
94 + struct ps_prochandle *pdb_ph; |
79 + struct ps_prochandle *pdb_ph; |
95 + int pdb_vers; |
80 + int pdb_vers; |
96 + int pdb_is_64bit; |
81 + int pdb_is_64bit; |
97 + int pdb_datamodel; |
82 + int pdb_datamodel; |
98 + const pydb_arch_ops_t *pdb_ops; |
|
99 +}; |
83 +}; |
100 + |
84 + |
101 +typedef uintptr_t (*pdi_next_cb_t)(pydb_iter_t *); |
85 +typedef uintptr_t (*pdi_next_cb_t)(pydb_iter_t *); |
102 + |
86 + |
103 +struct pydb_iter { |
87 +struct pydb_iter { |
104 + struct ps_prochandle *pdi_ph; |
88 + struct ps_prochandle *pdi_ph; |
105 + uintptr_t pdi_current; |
89 + uintptr_t pdi_current; |
106 + pdi_next_cb_t pdi_nextf; |
90 + pdi_next_cb_t pdi_nextf; |
107 +}; |
91 +}; |
108 + |
92 + |
109 +#define LIBPYTHON "libpython3.4.so" |
93 +#define LIBPYTHON "libpython3.4m.so" |
110 + |
94 + |
111 +#define MIN(x, y) (((x) < (y)) ? (x) : (y)) |
95 +#define MIN(x, y) (((x) < (y)) ? (x) : (y)) |
112 + |
96 + |
113 +/* Generic interface to helper functions */ |
97 +/* Generic interface to helper functions */ |
114 +static ssize_t pydb_strobj_readdata(pydb_agent_t *py, uintptr_t addr, |
98 +static ssize_t pydb_strobj_readdata(pydb_agent_t *py, uintptr_t addr, |
122 +static ssize_t pydb_strobj_readdata_native(pydb_agent_t *py, uintptr_t addr, |
106 +static ssize_t pydb_strobj_readdata_native(pydb_agent_t *py, uintptr_t addr, |
123 + unsigned char *buf, size_t buf_len); |
107 + unsigned char *buf, size_t buf_len); |
124 +static int pydb_frameinfo_native(pydb_agent_t *py, uintptr_t addr, char *funcnm, |
108 +static int pydb_frameinfo_native(pydb_agent_t *py, uintptr_t addr, char *funcnm, |
125 + size_t funcnm_sz, char *filenm, size_t filenm_sz, int *lineno); |
109 + size_t funcnm_sz, char *filenm, size_t filenm_sz, int *lineno); |
126 + |
110 + |
127 +#if defined (_LP64) |
|
128 +static ssize_t pydb_strobj_readdata_32(pydb_agent_t *py, uintptr_t addr, |
|
129 + unsigned char *buf, size_t buf_len); |
|
130 +static int pydb_frameinfo_32(pydb_agent_t *py, uintptr_t addr, char *funcnm, |
|
131 + size_t funcnm_sz, char *filenm, size_t filenm_sz, int *lineno); |
|
132 +#endif /* _LP64 */ |
|
133 + |
|
134 +static ssize_t pydb_strobj_readstr(pydb_agent_t *py, uintptr_t addr, char *buf, |
111 +static ssize_t pydb_strobj_readstr(pydb_agent_t *py, uintptr_t addr, char *buf, |
135 + size_t len); |
112 + size_t len); |
136 + |
113 + |
137 +/* Iterator function next routines. Plugable, configured by iterator init */ |
114 +/* Iterator function next routines. Plugable, configured by iterator init */ |
138 +static uintptr_t pydb_frame_iter_next(pydb_iter_t *iter); |
115 +static uintptr_t pydb_frame_iter_next(pydb_iter_t *iter); |
139 +static uintptr_t pydb_interp_iter_next(pydb_iter_t *iter); |
116 +static uintptr_t pydb_interp_iter_next(pydb_iter_t *iter); |
140 +static uintptr_t pydb_thread_iter_next(pydb_iter_t *iter); |
117 +static uintptr_t pydb_thread_iter_next(pydb_iter_t *iter); |
141 + |
118 + |
142 +static const char *strbasename(const char *s); |
119 +static const char *strbasename(const char *s); |
143 + |
120 + |
144 +static const pydb_arch_ops_t arch_ops_native = { |
|
145 + .frameinfo = pydb_frameinfo_native, |
|
146 + .strobj_readdata = pydb_strobj_readdata_native, |
|
147 +}; |
|
148 + |
|
149 +#if defined (_LP64) |
|
150 +static const pydb_arch_ops_t arch_ops_32 = { |
|
151 + .frameinfo = pydb_frameinfo_32, |
|
152 + .strobj_readdata = pydb_strobj_readdata_32, |
|
153 +}; |
|
154 +#endif /* _LP64 */ |
|
155 + |
|
156 +static const char * |
121 +static const char * |
157 +strbasename(const char *s) |
122 +strbasename(const char *s) |
158 +{ |
123 +{ |
159 + const char *p = strrchr(s, '/'); |
124 + const char *p = strrchr(s, '/'); |
160 + |
125 + |
244 + |
201 + |
245 + return (line); |
202 + return (line); |
246 +} |
203 +} |
247 + |
204 + |
248 +static ssize_t |
205 +static ssize_t |
249 +pydb_strobj_readdata(pydb_agent_t *py, uintptr_t addr, unsigned char *buf, |
206 +pydb_asciiobj_readdata(pydb_agent_t *py, uintptr_t addr, |
|
207 + unsigned char *buf, size_t buf_len) |
|
208 +{ |
|
209 + PyASCIIObject sobj; |
|
210 + ssize_t obj_sz; |
|
211 + ssize_t read_sz; |
|
212 + psaddr_t asciiaddr; |
|
213 + |
|
214 + /* |
|
215 + * PyASCIIObjects are a type of Unicode string. They are identified |
|
216 + * as follows: |
|
217 + * - sobj.state.compact == 1 |
|
218 + * - sobj.state.ascii == 1 |
|
219 + * - sobj.state.ready == 1 |
|
220 + * The length of the string is stored in sobj.length. The string |
|
221 + * itself follows the PyASCIIObject. |
|
222 + */ |
|
223 + |
|
224 + if (ps_pread(py->pdb_ph, addr, &sobj, sizeof (PyASCIIObject)) |
|
225 + != PS_OK) { |
|
226 + return (-1); |
|
227 + } |
|
228 + |
|
229 + if (!sobj.state.compact || !sobj.state.ascii || !sobj.state.ready) { |
|
230 + return (-1); |
|
231 + } |
|
232 + |
|
233 + obj_sz = (ssize_t)sobj.length; |
|
234 + |
|
235 + read_sz = MIN(obj_sz, (ssize_t)buf_len); |
|
236 + asciiaddr = (psaddr_t)(addr + sizeof (PyASCIIObject)); |
|
237 + |
|
238 + if (ps_pread(py->pdb_ph, asciiaddr, buf, (size_t)read_sz) != PS_OK) { |
|
239 + return (-1); |
|
240 + } |
|
241 + |
|
242 + return (read_sz); |
|
243 +} |
|
244 + |
|
245 +static ssize_t |
|
246 +pydb_asciiobj_readstr(pydb_agent_t *py, uintptr_t addr, char *buf, |
250 + size_t buf_len) |
247 + size_t buf_len) |
251 +{ |
248 +{ |
252 + return (py->pdb_ops->strobj_readdata(py, addr, buf, buf_len)); |
249 + ssize_t read_sz; |
|
250 + |
|
251 + read_sz = pydb_asciiobj_readdata(py, addr, (unsigned char *)buf, |
|
252 + buf_len); |
|
253 + |
|
254 + if (read_sz >= 0) { |
|
255 + if (read_sz >= buf_len) { |
|
256 + read_sz = buf_len - 1; |
|
257 + } |
|
258 + |
|
259 + buf[read_sz] = '\0'; |
|
260 + } |
|
261 + |
|
262 + return (read_sz); |
253 +} |
263 +} |
254 + |
264 + |
255 +static ssize_t |
265 +static ssize_t |
256 +pydb_strobj_readdata_native(pydb_agent_t *py, uintptr_t addr, |
266 +pydb_strobj_readdata(pydb_agent_t *py, uintptr_t addr, |
257 + unsigned char *buf, size_t buf_len) |
267 + unsigned char *buf, size_t buf_len) |
258 +{ |
268 +{ |
259 + PyBytesObject sobj; |
269 + PyBytesObject sobj; |
260 + ssize_t obj_sz; |
270 + ssize_t obj_sz; |
261 + ssize_t read_sz; |
271 + ssize_t read_sz; |
275 + if (ps_pread(py->pdb_ph, addr, &sobj, sizeof (PyBytesObject)) |
285 + if (ps_pread(py->pdb_ph, addr, &sobj, sizeof (PyBytesObject)) |
276 + != PS_OK) { |
286 + != PS_OK) { |
277 + return (-1); |
287 + return (-1); |
278 + } |
288 + } |
279 + |
289 + |
280 + obj_sz = (ssize_t)PyString_GET_SIZE(&sobj); |
290 + /* |
|
291 + * If we want to emulate PyBytes_GET_SIZE() instead of just calling |
|
292 + * Py_SIZE() directly, we need to do a ps_pread() of Py_TYPE(&sobj). |
|
293 + * PyBytes_Check() will try to access the type structure, but the |
|
294 + * address is not in the debugger's address space. |
|
295 + */ |
|
296 + obj_sz = (ssize_t)Py_SIZE(&sobj); |
281 + |
297 + |
282 + read_sz = MIN(obj_sz, (ssize_t)buf_len); |
298 + read_sz = MIN(obj_sz, (ssize_t)buf_len); |
283 + straddr = (psaddr_t)(addr + offsetof(PyBytesObject, ob_sval)); |
299 + straddr = (psaddr_t)(addr + offsetof(PyBytesObject, ob_sval)); |
284 + |
300 + |
285 + if (ps_pread(py->pdb_ph, straddr, buf, (size_t)read_sz) != PS_OK) { |
301 + if (ps_pread(py->pdb_ph, straddr, buf, (size_t)read_sz) != PS_OK) { |
286 + return (-1); |
302 + return (-1); |
287 + } |
303 + } |
288 + |
304 + |
289 + return (read_sz); |
305 + return (read_sz); |
290 +} |
306 +} |
291 + |
|
292 +#if defined(_LP64) |
|
293 +static ssize_t |
|
294 +pydb_strobj_readdata_32(pydb_agent_t *py, uintptr_t addr, |
|
295 + unsigned char *buf, size_t buf_len) |
|
296 +{ |
|
297 + PyBytesObject32 sobj; |
|
298 + ssize_t obj_sz; |
|
299 + ssize_t read_sz; |
|
300 + psaddr_t straddr; |
|
301 + |
|
302 + /* |
|
303 + * PyBytesObject are variable size. The size of the PyBytesObject |
|
304 + * struct is fixed, and known at compile time; however, the size of the |
|
305 + * associated buffer is variable. The char[1] element at the end of the |
|
306 + * structure contains the string, and the ob_size of the PyBytesObject |
|
307 + * indicates how much extra space was allocated to contain the string |
|
308 + * buffer at the object's tail. Read in the fixed size portion of the |
|
309 + * object first, and then read the contents of the data buffer into the |
|
310 + * buffer passed by the caller. |
|
311 + */ |
|
312 + |
|
313 + if (ps_pread(py->pdb_ph, addr, &sobj, sizeof (PyBytesObject32)) |
|
314 + != PS_OK) { |
|
315 + return (-1); |
|
316 + } |
|
317 + |
|
318 + obj_sz = (ssize_t)PyString_GET_SIZE32(&sobj); |
|
319 + |
|
320 + read_sz = MIN(obj_sz, (ssize_t)buf_len); |
|
321 + straddr = (psaddr_t)(addr + offsetof(PyBytesObject32, ob_sval)); |
|
322 + |
|
323 + if (ps_pread(py->pdb_ph, straddr, buf, (size_t)read_sz) != PS_OK) { |
|
324 + return (-1); |
|
325 + } |
|
326 + |
|
327 + return (read_sz); |
|
328 +} |
|
329 +#endif /* _LP64 */ |
|
330 + |
307 + |
331 +/* |
308 +/* |
332 + * Most Python PyBytesObject contain strings, as one would expect. However, |
309 + * Most Python PyBytesObject contain strings, as one would expect. However, |
333 + * due to some sleazy hackery in parts of the Python code, some string objects |
310 + * due to some sleazy hackery in parts of the Python code, some string objects |
334 + * are used as buffers for binary data. In the general case, |
311 + * are used as buffers for binary data. In the general case, |
358 + |
335 + |
359 +static int |
336 +static int |
360 +pydb_frameinfo(pydb_agent_t *py, uintptr_t addr, char *funcnm, |
337 +pydb_frameinfo(pydb_agent_t *py, uintptr_t addr, char *funcnm, |
361 + size_t funcnm_sz, char *filenm, size_t filenm_sz, int *lineno) |
338 + size_t funcnm_sz, char *filenm, size_t filenm_sz, int *lineno) |
362 +{ |
339 +{ |
363 + return (py->pdb_ops->frameinfo(py, addr, funcnm, funcnm_sz, |
|
364 + filenm, filenm_sz, lineno)); |
|
365 +} |
|
366 + |
|
367 +static int |
|
368 +pydb_frameinfo_native(pydb_agent_t *py, uintptr_t addr, char *funcnm, |
|
369 + size_t funcnm_sz, char *filenm, size_t filenm_sz, int *lineno) |
|
370 +{ |
|
371 + PyFrameObject fo; |
340 + PyFrameObject fo; |
372 + PyCodeObject co; |
341 + PyCodeObject co; |
373 + ssize_t rc; |
342 + ssize_t rc; |
374 + |
343 + |
375 + if (ps_pread(py->pdb_ph, addr, &fo, sizeof (PyFrameObject)) |
344 + if (ps_pread(py->pdb_ph, addr, &fo, sizeof (PyFrameObject)) |
380 + if (ps_pread(py->pdb_ph, (uintptr_t)fo.f_code, &co, |
349 + if (ps_pread(py->pdb_ph, (uintptr_t)fo.f_code, &co, |
381 + sizeof (PyCodeObject)) != PS_OK) { |
350 + sizeof (PyCodeObject)) != PS_OK) { |
382 + return (-1); |
351 + return (-1); |
383 + } |
352 + } |
384 + |
353 + |
385 + rc = pydb_strobj_readstr(py, (uintptr_t)co.co_name, funcnm, funcnm_sz); |
354 + rc = pydb_asciiobj_readstr(py, (uintptr_t)co.co_name, funcnm, |
|
355 + funcnm_sz); |
386 + if (rc < 0) { |
356 + if (rc < 0) { |
387 + return (-1); |
357 + return (-1); |
388 + } |
358 + } |
389 + |
359 + |
390 + rc = pydb_strobj_readstr(py, (uintptr_t)co.co_filename, filenm, |
360 + rc = pydb_asciiobj_readstr(py, (uintptr_t)co.co_filename, filenm, |
391 + filenm_sz); |
361 + filenm_sz); |
392 + if (rc < 0) { |
362 + if (rc < 0) { |
393 + return (-1); |
363 + return (-1); |
394 + } |
364 + } |
395 + |
365 + |
399 + return (-1); |
369 + return (-1); |
400 + } |
370 + } |
401 + |
371 + |
402 + return (0); |
372 + return (0); |
403 +} |
373 +} |
404 + |
|
405 +#if defined (_LP64) |
|
406 +static int |
|
407 +pydb_frameinfo_32(pydb_agent_t *py, uintptr_t addr, char *funcnm, |
|
408 + size_t funcnm_sz, char *filenm, size_t filenm_sz, int *lineno) |
|
409 +{ |
|
410 + PyFrameObject32 fo; |
|
411 + PyCodeObject32 co; |
|
412 + ssize_t rc; |
|
413 + |
|
414 + if (ps_pread(py->pdb_ph, addr, &fo, sizeof (PyFrameObject32)) |
|
415 + != PS_OK) { |
|
416 + return (-1); |
|
417 + } |
|
418 + |
|
419 + if (ps_pread(py->pdb_ph, (uintptr_t)fo.f_code, &co, |
|
420 + sizeof (PyCodeObject32)) != PS_OK) { |
|
421 + return (-1); |
|
422 + } |
|
423 + |
|
424 + rc = pydb_strobj_readstr(py, (uintptr_t)co.co_name, funcnm, funcnm_sz); |
|
425 + if (rc < 0) { |
|
426 + return (-1); |
|
427 + } |
|
428 + |
|
429 + rc = pydb_strobj_readstr(py, (uintptr_t)co.co_filename, filenm, |
|
430 + filenm_sz); |
|
431 + if (rc < 0) { |
|
432 + return (-1); |
|
433 + } |
|
434 + |
|
435 + *lineno = pydb_getlno(py, (uintptr_t)co.co_lnotab, co.co_firstlineno, |
|
436 + fo.f_lasti); |
|
437 + if (*lineno < 0) { |
|
438 + return (-1); |
|
439 + } |
|
440 + |
|
441 + return (0); |
|
442 +} |
|
443 + |
|
444 +#endif /* _LP64 */ |
|
445 + |
374 + |
446 +/* Functions that are part of the library's interface */ |
375 +/* Functions that are part of the library's interface */ |
447 + |
376 + |
448 +/* |
377 +/* |
449 + * Given the address of a PyFrameObject, and a buffer of a known size, |
378 + * Given the address of a PyFrameObject, and a buffer of a known size, |