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