annotate .gdbinit @ 159:c3c3dd60b8a8

demo of slurm usage using cdx2tsv.py
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Wed, 06 Jul 2022 18:07:34 +0100
parents d39fd9c7f1be
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
63
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
1 # -*- ksh -*-
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
2 #
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
3 # If you use the GNU debugger gdb to debug the Python C runtime, you
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
4 # might find some of the following commands useful. Copy this to your
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
5 # ~/.gdbinit file and it'll get loaded into gdb automatically when you
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
6 # start it up. Then, at the gdb prompt you can do things like:
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
7 #
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
8 # (gdb) pyo apyobjectptr
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
9 # <module 'foobar' (built-in)>
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
10 # refcounts: 1
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
11 # address : 84a7a2c
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
12 # $1 = void
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
13 # (gdb)
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
14
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
15 # Prints a representation of the object to stderr, along with the
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
16 # number of reference counts it current has and the hex address the
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
17 # object is allocated at. The argument must be a PyObject*
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
18 define pyo
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
19 print _PyObject_Dump($arg0)
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
20 end
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
21
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
22 # Prints a representation of the object to stderr, along with the
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
23 # number of reference counts it current has and the hex address the
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
24 # object is allocated at. The argument must be a PyGC_Head*
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
25 define pyg
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
26 print _PyGC_Dump($arg0)
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
27 end
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
28
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
29 # print the local variables of the current frame
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
30 define pylocals
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
31 set $_i = 0
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
32 while $_i < f->f_code->co_nlocals
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
33 if f->f_localsplus + $_i != 0
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
34 set $_names = co->co_varnames
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
35 set $_name = PyString_AsString(PyTuple_GetItem($_names, $_i))
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
36 printf "%s:\n", $_name
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
37 # side effect of calling _PyObject_Dump is to dump the object's
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
38 # info - assigning just prevents gdb from printing the
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
39 # NULL return value
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
40 set $_val = _PyObject_Dump(f->f_localsplus[$_i])
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
41 end
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
42 set $_i = $_i + 1
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
43 end
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
44 end
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
45
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
46 # A rewrite of the Python interpreter's line number calculator in GDB's
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
47 # command language
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
48 define lineno
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
49 set $__continue = 1
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
50 set $__co = f->f_code
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
51 set $__lasti = f->f_lasti
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
52 set $__sz = ((PyStringObject *)$__co->co_lnotab)->ob_size/2
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
53 set $__p = (unsigned char *)((PyStringObject *)$__co->co_lnotab)->ob_sval
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
54 set $__li = $__co->co_firstlineno
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
55 set $__ad = 0
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
56 while ($__sz-1 >= 0 && $__continue)
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
57 set $__sz = $__sz - 1
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
58 set $__ad = $__ad + *$__p
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
59 set $__p = $__p + 1
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
60 if ($__ad > $__lasti)
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
61 set $__continue = 0
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
62 end
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
63 set $__li = $__li + *$__p
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
64 set $__p = $__p + 1
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
65 end
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
66 printf "%d", $__li
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
67 end
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
68
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
69 # print the current frame - verbose
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
70 define pyframev
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
71 pyframe
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
72 pylocals
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
73 end
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
74
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
75 define pyframe
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
76 set $__fn = (char *)((PyStringObject *)co->co_filename)->ob_sval
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
77 set $__n = (char *)((PyStringObject *)co->co_name)->ob_sval
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
78 printf "%s (", $__fn
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
79 lineno
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
80 printf "): %s\n", $__n
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
81 ### Uncomment these lines when using from within Emacs/XEmacs so it will
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
82 ### automatically track/display the current Python source line
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
83 # printf "%c%c%s:", 032, 032, $__fn
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
84 # lineno
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
85 # printf ":1\n"
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
86 end
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
87
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
88 ### Use these at your own risk. It appears that a bug in gdb causes it
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
89 ### to crash in certain circumstances.
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
90
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
91 #define up
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
92 # up-silently 1
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
93 # printframe
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
94 #end
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
95
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
96 #define down
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
97 # down-silently 1
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
98 # printframe
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
99 #end
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
100
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
101 define printframe
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
102 if $pc > PyEval_EvalFrameEx && $pc < PyEval_EvalCodeEx
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
103 pyframe
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
104 else
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
105 frame
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
106 end
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
107 end
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
108
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
109 # Here's a somewhat fragile way to print the entire Python stack from gdb.
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
110 # It's fragile because the tests for the value of $pc depend on the layout
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
111 # of specific functions in the C source code.
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
112
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
113 # Explanation of while and if tests: We want to pop up the stack until we
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
114 # land in Py_Main (this is probably an incorrect assumption in an embedded
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
115 # interpreter, but the test can be extended by an interested party). If
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
116 # Py_Main <= $pc <= Py_GetArgcArv is true, $pc is in Py_Main(), so the while
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
117 # tests succeeds as long as it's not true. In a similar fashion the if
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
118 # statement tests to see if we are in PyEval_EvalFrameEx().
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
119
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
120 # Note: The name of the main interpreter function and the function which
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
121 # follow it has changed over time. This version of pystack works with this
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
122 # version of Python. If you try using it with older or newer versions of
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
123 # the interpreter you may will have to change the functions you compare with
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
124 # $pc.
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
125
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
126 # print the entire Python call stack
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
127 define pystack
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
128 while $pc < Py_Main || $pc > Py_GetArgcArgv
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
129 if $pc > PyEval_EvalFrameEx && $pc < PyEval_EvalCodeEx
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
130 pyframe
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
131 end
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
132 up-silently 1
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
133 end
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
134 select-frame 0
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
135 end
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
136
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
137 # print the entire Python call stack - verbose mode
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
138 define pystackv
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
139 while $pc < Py_Main || $pc > Py_GetArgcArgv
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
140 if $pc > PyEval_EvalFrameEx && $pc < PyEval_EvalCodeEx
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
141 pyframev
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
142 end
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
143 up-silently 1
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
144 end
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
145 select-frame 0
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
146 end
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
147
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
148 # generally useful macro to print a Unicode string
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
149 def pu
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
150 set $uni = $arg0
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
151 set $i = 0
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
152 while (*$uni && $i++<100)
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
153 if (*$uni < 0x80)
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
154 print *(char*)$uni++
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
155 else
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
156 print /x *(short*)$uni++
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
157 end
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
158 end
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
159 end