Aurelien Larcher
2021-01-08 b5a8497ec9558d0061024ac4b49f445bbe7d1094
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
This patch adds Python debugger support.  It may be contributed upstream at
some point, but the suitability (or lack thereof) has not yet been determined.
 
--- Python-3.9.1/Makefile.pre.in
+++ Python-3.9.1/Makefile.pre.in
@@ -472,7 +472,7 @@ DTRACE_DEPS = \
 # Default target
 all:        @DEF_MAKE_ALL_RULE@
 build_all:    check-clean-src $(BUILDPYTHON) oldsharedmods sharedmods gdbhooks \
-        Programs/_testembed python-config
+        Programs/_testembed python-config build-py_db
 
 # Check that the source is clean when building out of source.
 check-clean-src:
@@ -720,6 +720,15 @@ Makefile Modules/config.c: Makefile.pre
     @mv config.c Modules
     @echo "The Makefile was updated, you may need to re-run make."
 
+SHLIB_FLAGS = -shared -fpic
+
+libpython$(LDVERSION)_db.so.1.0:        $(srcdir)/py_db/libpython39_db.c
+    $(CC) -o $@ $(CFLAGS) $(PY_CPPFLAGS) $(CPPFLAGS) $(SHLIB_FLAGS) $<
+
+build-py_db:   libpython$(LDVERSION)_db.so.1.0
+
+install-py_db: libpython$(LDVERSION)_db.so.1.0
+    $(INSTALL_SHARED) libpython$(LDVERSION)_db.so.1.0 $(DESTDIR)$(LIBDIR)
 
 Programs/_testembed: Programs/_testembed.o $(LIBRARY) $(LDLIBRARY) $(PY3LIBRARY) $(EXPORTSYMS)
     $(LINKCC) $(PY_CORE_LDFLAGS) $(LINKFORSHARED) -o $@ Programs/_testembed.o $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS)
@@ -1239,7 +1248,7 @@ multisslcompile: build_all
 multissltest: build_all
     $(RUNSHARED) ./$(BUILDPYTHON) Tools/ssl/multissltests.py
 
-install: @FRAMEWORKINSTALLFIRST@ commoninstall bininstall maninstall @FRAMEWORKINSTALLLAST@
+install: @FRAMEWORKINSTALLFIRST@ commoninstall bininstall maninstall install-py_db @FRAMEWORKINSTALLLAST@
     if test "x$(ENSUREPIP)" != "xno"  ; then \
         case $(ENSUREPIP) in \
             upgrade) ensurepip="--upgrade" ;; \
--- Python-3.9.1/py_db/libpython39_db.c
+++ Python-3.9.1/py_db/libpython39_db.c
@@ -0,0 +1,596 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright (c) 2012, 2020, Oracle and/or its affiliates.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <gelf.h>
+
+#define Py_BUILD_CORE
+
+#include <Python.h>
+#include <frameobject.h>
+#include "internal/pycore_runtime.h"
+#include "internal/pycore_interp.h"
+
+#include "libpython39_db.h"
+
+struct pydb_agent {
+    struct ps_prochandle *pdb_ph;
+    int pdb_vers;
+    int pdb_is_64bit;
+    int pdb_datamodel;
+};
+
+typedef uintptr_t (*pdi_next_cb_t)(pydb_iter_t *);
+
+struct pydb_iter {
+    struct ps_prochandle *pdi_ph;
+    uintptr_t pdi_current;
+    pdi_next_cb_t pdi_nextf;
+};
+
+#define    LIBPYTHON    "libpython3.9.so"
+
+#define    MIN(x, y)    (((x) < (y)) ? (x) : (y))
+
+/* Generic interface to helper functions */
+static ssize_t pydb_strobj_readdata(pydb_agent_t *py, uintptr_t addr,
+    unsigned char *buf, size_t buf_len);
+static int pydb_getlno(pydb_agent_t *py, uintptr_t lnotab_addr, int firstline,
+    int lastinst);
+static int pydb_frameinfo(pydb_agent_t *py, uintptr_t addr, char *funcnm,
+    size_t funcnm_sz, char *filenm, size_t filenm_sz, int *lineno);
+
+/* datamodel specific implementation of helper functions */
+static ssize_t pydb_strobj_readdata_native(pydb_agent_t *py, uintptr_t addr,
+    unsigned char *buf, size_t buf_len);
+static int pydb_frameinfo_native(pydb_agent_t *py, uintptr_t addr, char *funcnm,
+    size_t funcnm_sz, char *filenm, size_t filenm_sz, int *lineno);
+
+static ssize_t pydb_strobj_readstr(pydb_agent_t *py, uintptr_t addr, char *buf,
+    size_t len);
+
+/* Iterator function next routines.  Plugable, configured by iterator init */
+static uintptr_t pydb_frame_iter_next(pydb_iter_t *iter);
+static uintptr_t pydb_interp_iter_next(pydb_iter_t *iter);
+static uintptr_t pydb_thread_iter_next(pydb_iter_t *iter);
+
+static const char *strbasename(const char *s);
+
+static const char *
+strbasename(const char *s)
+{
+    const char *p = strrchr(s, '/');
+
+    if (p == NULL)
+        return (s);
+
+    return (++p);
+}
+
+/* Agent creation / destruction routines */
+
+pydb_agent_t *
+pydb_agent_create(struct ps_prochandle *P, int vers)
+{
+    pydb_agent_t *py;
+    int datamodel;
+
+    if (vers != PYDB_VERSION) {
+        errno = ENOTSUP;
+        return (NULL);
+    }
+
+    if (ps_pdmodel(P, &datamodel) != PS_OK) {
+        return (NULL);
+    }
+
+    py = (pydb_agent_t *)malloc(sizeof (pydb_agent_t));
+    if (py == NULL) {
+        return (NULL);
+    }
+
+    py->pdb_ph = P;
+    py->pdb_vers = vers;
+    py->pdb_datamodel = datamodel;
+    py->pdb_is_64bit = 0;
+
+    return (py);
+}
+
+void
+pydb_agent_destroy(pydb_agent_t *py)
+{
+    if (py == NULL) {
+        return;
+    }
+
+    free(py);
+}
+
+/* Helper functions */
+static int
+pydb_getlno(pydb_agent_t *py, uintptr_t lnotab_addr, int firstline,
+    int lastinst)
+{
+    unsigned char lnotab[4096];
+    ssize_t lnotab_len;
+    int addr, line;
+    int i;
+
+    lnotab_len = pydb_strobj_readdata(py, lnotab_addr, lnotab,
+        sizeof (lnotab));
+    if (lnotab_len < 0) {
+        return (-1);
+    }
+
+    /*
+     * Python's line number algorithm is arcane. See here for details:
+     * http://svn.python.org/projects/python/trunk/Objects/lnotab_notes.txt
+     */
+
+    line = firstline;
+    for (addr = i = 0; i < lnotab_len; i += 2) {
+        if (addr + lnotab[i] > lastinst) {
+            break;
+        }
+        addr += lnotab[i];
+        line += lnotab[i + 1];
+    }
+
+    return (line);
+}
+
+static ssize_t
+pydb_asciiobj_readdata(pydb_agent_t *py, uintptr_t addr,
+    unsigned char *buf, size_t buf_len)
+{
+    PyASCIIObject sobj;
+    ssize_t obj_sz;
+    ssize_t read_sz;
+    psaddr_t asciiaddr;
+
+    /*
+     * PyASCIIObjects are a type of Unicode string.  They are identified
+     * as follows:
+     * - sobj.state.compact == 1
+     * - sobj.state.ascii == 1
+     * - sobj.state.ready == 1
+     * The length of the string is stored in sobj.length.  The string
+     * itself follows the PyASCIIObject.
+     */
+
+    if (ps_pread(py->pdb_ph, addr, &sobj, sizeof (PyASCIIObject))
+        != PS_OK) {
+        return (-1);
+    }
+
+    if (!sobj.state.compact || !sobj.state.ascii || !sobj.state.ready) {
+        return (-1);
+    }
+
+    obj_sz = (ssize_t)sobj.length;
+
+    read_sz = MIN(obj_sz, (ssize_t)buf_len);
+    asciiaddr = (psaddr_t)(addr + sizeof (PyASCIIObject));
+
+    if (ps_pread(py->pdb_ph, asciiaddr, buf, (size_t)read_sz) != PS_OK) {
+        return (-1);
+    }
+
+    return (read_sz);
+}
+
+static ssize_t
+pydb_asciiobj_readstr(pydb_agent_t *py, uintptr_t addr, char *buf,
+    size_t buf_len)
+{
+    ssize_t read_sz;
+
+    read_sz = pydb_asciiobj_readdata(py, addr, (unsigned char *)buf,
+        buf_len);
+
+    if (read_sz >= 0) {
+        if (read_sz >= buf_len) {
+            read_sz = buf_len - 1;
+        }
+
+        buf[read_sz] = '\0';
+    }
+
+    return (read_sz);
+}
+
+static ssize_t
+pydb_strobj_readdata(pydb_agent_t *py, uintptr_t addr,
+    unsigned char *buf, size_t buf_len)
+{
+    PyBytesObject sobj;
+    ssize_t obj_sz;
+    ssize_t read_sz;
+    psaddr_t straddr;
+
+    /*
+     * PyBytesObject are variable size.  The size of the PyBytesObject
+     * struct is fixed, and known at compile time; however, the size of the
+     * associated buffer is variable.  The char[1] element at the end of the
+     * structure contains the string, and the ob_size of the PyBytesObject
+     * indicates how much extra space was allocated to contain the string
+     * buffer at the object's tail.  Read in the fixed size portion of the
+     * object first, and then read the contents of the data buffer into the
+     * buffer passed by the caller.
+     */
+
+    if (ps_pread(py->pdb_ph, addr, &sobj, sizeof (PyBytesObject))
+        != PS_OK) {
+        return (-1);
+    }
+
+    /*
+     * If we want to emulate PyBytes_GET_SIZE() instead of just calling
+     * Py_SIZE() directly, we need to do a ps_pread() of Py_TYPE(&sobj).
+     * PyBytes_Check() will try to access the type structure, but the 
+     * address is not in the debugger's address space.
+     */
+    obj_sz = (ssize_t)Py_SIZE(&sobj);
+
+    read_sz = MIN(obj_sz, (ssize_t)buf_len);
+    straddr = (psaddr_t)(addr + offsetof(PyBytesObject, ob_sval));
+
+    if (ps_pread(py->pdb_ph, straddr, buf, (size_t)read_sz) != PS_OK) {
+        return (-1);
+    }
+
+    return (read_sz);
+}
+
+/*
+ * Most Python PyBytesObject contain strings, as one would expect.  However,
+ * due to some sleazy hackery in parts of the Python code, some string objects
+ * are used as buffers for binary data.  In the general case,
+ * pydb_strobj_readstr() should be used to read strings out of string objects.
+ * It wraps pydb_strobj_readdata(), which should be used by callers only when
+ * trying to retrieve binary data.  (This routine does some string cleanup).
+ */
+static ssize_t
+pydb_strobj_readstr(pydb_agent_t *py, uintptr_t addr, char *buf,
+    size_t buf_len)
+{
+    ssize_t read_sz;
+
+    read_sz = pydb_strobj_readdata(py, addr, (unsigned char *)buf, buf_len);
+
+    if (read_sz >= 0) {
+        if (read_sz >= buf_len) {
+            read_sz = buf_len - 1;
+        }
+
+        buf[read_sz] = '\0';
+    }
+
+    return (read_sz);
+}
+
+
+static int
+pydb_frameinfo(pydb_agent_t *py, uintptr_t addr, char *funcnm,
+    size_t funcnm_sz, char *filenm, size_t filenm_sz, int *lineno)
+{
+    PyFrameObject fo;
+    PyCodeObject co;
+    ssize_t rc;
+
+    if (ps_pread(py->pdb_ph, addr, &fo, sizeof (PyFrameObject))
+        != PS_OK) {
+        return (-1);
+    }
+
+    if (ps_pread(py->pdb_ph, (uintptr_t)fo.f_code, &co,
+        sizeof (PyCodeObject)) != PS_OK) {
+        return (-1);
+    }
+
+    rc = pydb_asciiobj_readstr(py, (uintptr_t)co.co_name, funcnm,
+        funcnm_sz);
+    if (rc < 0) {
+        return (-1);
+    }
+
+    rc = pydb_asciiobj_readstr(py, (uintptr_t)co.co_filename, filenm,
+        filenm_sz);
+    if (rc < 0) {
+        return (-1);
+    }
+
+    *lineno = pydb_getlno(py, (uintptr_t)co.co_lnotab, co.co_firstlineno,
+        fo.f_lasti);
+    if (*lineno < 0) {
+        return (-1);
+    }
+
+    return (0);
+}
+
+/* Functions that are part of the library's interface */
+
+/*
+ * Given the address of a PyFrameObject, and a buffer of a known size,
+ * fill the buffer with a description of the frame.
+ */
+int
+pydb_get_frameinfo(pydb_agent_t *py, uintptr_t frame_addr, char *fbuf,
+    size_t bufsz, int verbose)
+{
+    char funcname[1024];
+    char filename[1024];
+    char *fn;
+    int lineno;
+    int length = (py->pdb_is_64bit ? 16 : 8);
+    int rc;
+
+    rc = pydb_frameinfo(py, frame_addr, funcname, sizeof (funcname),
+        filename, sizeof (filename), &lineno);
+    if (rc < 0) {
+        return (-1);
+    }
+
+    if (!verbose) {
+        fn = (char *)strbasename(filename);
+    } else {
+        fn = filename;
+    }
+
+    (void) snprintf(fbuf, bufsz, "%0.*lx %s:%d %s()\n", length,
+        frame_addr, fn, lineno, funcname);
+
+    return (0);
+}
+
+/*
+ * Return a description about a PyFrameObject, if the object is
+ * actually a PyFrameObject.  In this case, the pc argument is checked
+ * to make sure that it came from a function that takes a PyFrameObject
+ * as its first (argv[0]) argument.
+ */
+int
+pydb_pc_frameinfo(pydb_agent_t *py, uintptr_t pc, uintptr_t frame_addr,
+    char *fbuf, size_t bufsz)
+{
+    char funcname[1024];
+    char filename[1024];
+    int lineno;
+    int rc;
+    ps_sym_t psym;
+
+    /*
+     * If PC doesn't match PyEval_EvalFrameEx in either libpython
+     * or the executable, don't decode it.
+     */
+    if (ps_pglobal_sym(py->pdb_ph, LIBPYTHON, "PyEval_EvalFrameEx", &psym)
+        != PS_OK) {
+        return (-1);
+    }
+
+    /* If symbol found, ensure that PC falls within PyEval_EvalFrameEx. */
+    if (pc < psym.st_value || pc > psym.st_value + psym.st_size) {
+        return (-1);
+    }
+
+    rc = pydb_frameinfo(py, frame_addr, funcname, sizeof (funcname),
+        filename, sizeof (filename), &lineno);
+    if (rc < 0) {
+        return (-1);
+    }
+
+    (void) snprintf(fbuf, bufsz, "[ %s:%d (%s) ]\n", filename, lineno,
+        funcname);
+
+    return (0);
+}
+
+/*
+ * Walks the list of PyInterpreterState objects.  If caller doesn't
+ * supply address of list, this method will look it up.
+ */
+pydb_iter_t *
+pydb_interp_iter_init(pydb_agent_t *py, uintptr_t addr)
+{
+    pydb_iter_t *itr;
+    _PyRuntimeState st;
+    uintptr_t i_addr;
+    int rc;
+
+    if (addr == 0) {
+        rc = ps_pglobal_lookup(py->pdb_ph, LIBPYTHON, "_PyRuntime",
+            (psaddr_t *)&addr);
+        if (rc != PS_OK) {
+            return (NULL);
+        }
+
+        if (ps_pread(py->pdb_ph, (uintptr_t)addr, &st, sizeof (_PyRuntimeState))
+            != PS_OK) {
+            return (NULL);
+        }
+
+        i_addr = (uintptr_t)st.interpreters.head;
+
+    } else {
+        if (ps_pread(py->pdb_ph, (uintptr_t)addr, &i_addr, sizeof (uintptr_t))
+            != PS_OK) {
+            return (NULL);
+        }
+    }
+
+    itr = malloc(sizeof (pydb_iter_t));
+    if (itr == NULL) {
+        return (NULL);
+    }
+
+    itr->pdi_ph = py->pdb_ph;
+    itr->pdi_current = i_addr;
+    itr->pdi_nextf = pydb_interp_iter_next;
+
+    return (itr);
+}
+
+static uintptr_t
+pydb_interp_iter_next(pydb_iter_t *iter)
+{
+    PyInterpreterState st;
+    uintptr_t cur;
+
+    cur = iter->pdi_current;
+
+    if (cur == 0) {
+        return (cur);
+    }
+
+    if (ps_pread(iter->pdi_ph, cur, &st, sizeof (PyInterpreterState))
+        != PS_OK) {
+        iter->pdi_current = 0;
+        return (0);
+    }
+
+    iter->pdi_current = (uintptr_t)st.next;
+
+    return (cur);
+}
+
+/*
+ * Walk a list of Python PyFrameObjects.  The addr argument must be
+ * the address of a valid PyThreadState object.
+ */
+pydb_iter_t *
+pydb_frame_iter_init(pydb_agent_t *py, uintptr_t addr)
+{
+    pydb_iter_t *itr;
+    PyThreadState ts;
+
+    if (ps_pread(py->pdb_ph, (uintptr_t)addr, &ts, sizeof (PyThreadState))
+        != PS_OK) {
+        return (NULL);
+    }
+
+    itr = malloc(sizeof (pydb_iter_t));
+    if (itr == NULL) {
+        return (NULL);
+    }
+
+    itr->pdi_ph = py->pdb_ph;
+    itr->pdi_current = (uintptr_t)ts.frame;
+    itr->pdi_nextf = pydb_frame_iter_next;
+
+    return (itr);
+}
+
+static uintptr_t
+pydb_frame_iter_next(pydb_iter_t *iter)
+{
+    PyFrameObject fo;
+    uintptr_t cur;
+
+    cur = iter->pdi_current;
+
+    if (cur == 0) {
+        return (cur);
+    }
+
+    if (ps_pread(iter->pdi_ph, cur, &fo, sizeof (PyFrameObject))
+        != PS_OK) {
+        iter->pdi_current = 0;
+        return (0);
+    }
+
+    iter->pdi_current = (uintptr_t)fo.f_back;
+
+    return (cur);
+}
+
+/*
+ * Walk a list of Python PyThreadState objects.  The addr argument must be
+ * the address of a valid PyInterpreterState object.
+ */
+pydb_iter_t *
+pydb_thread_iter_init(pydb_agent_t *py, uintptr_t addr)
+{
+    pydb_iter_t *itr;
+    PyInterpreterState is;
+
+    if (ps_pread(py->pdb_ph, (uintptr_t)addr, &is,
+        sizeof (PyInterpreterState)) != PS_OK) {
+        return (NULL);
+    }
+
+    itr = malloc(sizeof (pydb_iter_t));
+    if (itr == NULL) {
+        return (NULL);
+    }
+
+    itr->pdi_ph = py->pdb_ph;
+    itr->pdi_current = (uintptr_t)is.tstate_head;
+    itr->pdi_nextf = pydb_thread_iter_next;
+
+    return (itr);
+}
+
+static uintptr_t
+pydb_thread_iter_next(pydb_iter_t *iter)
+{
+    PyThreadState ts;
+    uintptr_t cur;
+
+    cur = iter->pdi_current;
+
+    if (cur == 0) {
+        return (cur);
+    }
+
+    if (ps_pread(iter->pdi_ph, cur, &ts, sizeof (PyThreadState)) != PS_OK) {
+        iter->pdi_current = 0;
+        return (0);
+    }
+
+    iter->pdi_current = (uintptr_t)ts.next;
+
+    return (cur);
+}
+
+
+uintptr_t
+pydb_iter_next(pydb_iter_t *iter)
+{
+    return (iter->pdi_nextf(iter));
+}
+
+void
+pydb_iter_fini(pydb_iter_t *iter)
+{
+    if (iter == NULL) {
+        return;
+    }
+
+    free(iter);
+}
--- Python-3.9.1/py_db/libpython39_db.h
+++ Python-3.9.1/py_db/libpython39_db.h
@@ -0,0 +1,73 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright (c) 2012, 2020, Oracle and/or its affiliates.
+ */
+
+#ifndef    _LIBPYTHON39_DB_H
+#define    _LIBPYTHON39_DB_H
+
+#include <proc_service.h>
+
+#ifdef    __cplusplus
+extern "C" {
+#endif
+
+/* Agent is opaque to library's consumers.  */
+typedef struct pydb_agent pydb_agent_t;
+
+/*
+ * Library's debug version is 1.  Changes to interface should increase this
+ * number.
+ */
+#define    PYDB_VERSION    1
+
+/* Agent creation/destruction routines */
+extern    pydb_agent_t    *pydb_agent_create(struct ps_prochandle *P, int vers);
+extern    void        pydb_agent_destroy(pydb_agent_t *py);
+
+/* Used by callers that know they are looking at a PyFrameObject */
+extern    int    pydb_get_frameinfo(pydb_agent_t *py, uintptr_t frame_addr,
+    char *fbuf, size_t bufsz, int verbose);
+
+/*
+ * Used by callers that don't know if they're looking at PyFrameObject.
+ * Checks PC for traceable functions.
+ */
+extern    int    pydb_pc_frameinfo(pydb_agent_t *py, uintptr_t pc,
+    uintptr_t frame_addr, char *fbuf, size_t bufsz);
+
+/* Iterator functions */
+typedef struct pydb_iter pydb_iter_t;
+
+extern    pydb_iter_t    *pydb_frame_iter_init(pydb_agent_t *py, uintptr_t addr);
+extern    pydb_iter_t    *pydb_interp_iter_init(pydb_agent_t *py,
+    uintptr_t addr);
+extern    pydb_iter_t    *pydb_thread_iter_init(pydb_agent_t *py,
+    uintptr_t addr);
+extern    void        pydb_iter_fini(pydb_iter_t *iter);
+extern    uintptr_t    pydb_iter_next(pydb_iter_t *iter);
+
+#ifdef    __cplusplus
+}
+#endif
+
+#endif    /* _LIBPYTHON39_DB_H */
--- Python-3.9.1/py_db/mapfile-vers
+++ Python-3.9.1/py_db/mapfile-vers
@@ -0,0 +1,39 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright (c) 2012, 2020, Oracle and/or its affiliates.
+#
+
+SUNWprivate_1.1 {
+    global:
+    pydb_agent_create;
+    pydb_agent_destroy;
+    pydb_frame_iter_init;
+    pydb_get_frameinfo;
+    pydb_pc_frameinfo;
+    pydb_interp_iter_init;
+    pydb_thread_iter_init;
+    pydb_iter_fini;
+    pydb_iter_next;
+    local:
+    *;
+};