Skip to content

Commit 060701e

Browse files
committed
Create a MI -exec-kill command.
1 parent 0b53706 commit 060701e

6 files changed

Lines changed: 253 additions & 0 deletions

File tree

src/resources/mi-python/MIKill.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import re
2+
3+
#
4+
# Python MI command to support gdb's "kill" commands.
5+
#
6+
# https://sourceware.org/bugzilla/show_bug.cgi?id=31090
7+
# https://stackoverflow.com/questions/9669025/gdb-exit-program-without-exiting-gdb
8+
9+
10+
class MIKill(gdb.MICommand):
11+
"""
12+
Run the 'kill' command.
13+
14+
-exec-kill Kill the child process in which your program is running under GDB.
15+
-exec-kill-inferiors Kill the inferior or inferiors identified by GDB inferior number(s) infno.
16+
17+
See:
18+
https://sourceware.org/gdb/current/onlinedocs/gdb.html/Kill-Process.html
19+
https://sourceware.org/gdb/current/onlinedocs/gdb.html/Inferiors-Connections-and-Programs.html#Inferiors-Connections-and-Programs
20+
"""
21+
22+
def __init__(self, name, mode):
23+
self._mode = mode
24+
super(MIKill, self).__init__(name)
25+
26+
def invoke(self, argv):
27+
if self._mode == "kill":
28+
gdb.execute ("kill" + " ".join(argv), to_string=True)
29+
return None
30+
elif self._mode == "killinferiors":
31+
gdb.execute ("kill inferiors" + " ".join(argv), to_string=True)
32+
return None
33+
else:
34+
raise gdb.GdbError("kill: Invalid parameter: %s" % self._mode)
35+
36+
MIKill("-exec-kill", "kill")
37+
MIKill("-exec-kill-inferiors", "killinferiors")
38+

tests/hellofft/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hellofft

tests/hellofft/MIKill.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import re
2+
3+
#
4+
# Python MI command to support gdb's "kill" commands.
5+
#
6+
# https://sourceware.org/bugzilla/show_bug.cgi?id=31090
7+
# https://stackoverflow.com/questions/9669025/gdb-exit-program-without-exiting-gdb
8+
9+
10+
class MIKill(gdb.MICommand):
11+
"""
12+
Run the 'kill' command.
13+
14+
-exec-kill Kill the child process in which your program is running under GDB.
15+
-exec-kill-inferiors Kill the inferior or inferiors identified by GDB inferior number(s) infno.
16+
17+
See:
18+
https://sourceware.org/gdb/current/onlinedocs/gdb.html/Kill-Process.html
19+
https://sourceware.org/gdb/current/onlinedocs/gdb.html/Inferiors-Connections-and-Programs.html#Inferiors-Connections-and-Programs
20+
"""
21+
22+
def __init__(self, name, mode):
23+
self._mode = mode
24+
super(MIKill, self).__init__(name)
25+
26+
def invoke(self, argv):
27+
if self._mode == "kill":
28+
gdb.execute ("kill" + " ".join(argv), to_string=True)
29+
return None
30+
elif self._mode == "killinferiors":
31+
gdb.execute ("kill inferiors" + " ".join(argv), to_string=True)
32+
return None
33+
else:
34+
raise gdb.GdbError("kill: Invalid parameter: %s" % self._mode)
35+
36+
MIKill("-exec-kill", "kill")
37+
MIKill("-exec-kill-inferiors", "killinferiors")
38+

tests/hellofft/Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.PHONY: all
2+
all: hellofft
3+
4+
hellofft: hellofft.c
5+
gcc -g -o hellofft hellofft.c -lm
6+
7+
.PHONY: clean
8+
clean:
9+
rm -f hellofft
10+

tests/hellofft/hellofft.c

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/* Factored discrete Fourier transform, or FFT, and its inverse iFFT */
2+
3+
#include <assert.h>
4+
#include <math.h>
5+
#include <stdio.h>
6+
#include <stdlib.h>
7+
8+
#define q 15 /* for 2^3 points */
9+
#define N (1<<q) /* N-point FFT, iFFT */
10+
11+
typedef float real;
12+
typedef struct{real Re; real Im;} complex;
13+
14+
#ifndef PI
15+
# define PI 3.14159265358979323846264338327950288
16+
#endif
17+
18+
19+
/* Print a vector of complexes as ordered pairs. */
20+
static void print_vector( const char *title, complex *x, int n) {
21+
22+
int i;
23+
24+
printf("%s (dim=%d):", title, n);
25+
26+
for(i=0; i<(n<8?n:8); i++ ) {
27+
printf(" %5.2f,%5.2f ", x[i].Re,x[i].Im);
28+
}
29+
30+
putchar('\n');
31+
32+
return;
33+
}
34+
35+
/*
36+
fft(v,N):
37+
[0] If N==1 then return.
38+
[1] For k = 0 to N/2-1, let ve[k] = v[2*k]
39+
[2] Compute fft(ve, N/2);
40+
[3] For k = 0 to N/2-1, let vo[k] = v[2*k+1]
41+
[4] Compute fft(vo, N/2);
42+
[5] For m = 0 to N/2-1, do [6] through [9]
43+
[6] Let w.re = cos(2*PI*m/N)
44+
[7] Let w.im = -sin(2*PI*m/N)
45+
[8] Let v[m] = ve[m] + w*vo[m]
46+
[9] Let v[m+N/2] = ve[m] - w*vo[m]
47+
*/
48+
void fft( complex *v, int n, complex *tmp ) {
49+
50+
if(n>1) { /* otherwise, do nothing and return */
51+
int k,m; complex z, w, *vo, *ve;
52+
ve = tmp; vo = tmp+n/2;
53+
for(k=0; k<n/2; k++) {
54+
ve[k] = v[2*k];
55+
vo[k] = v[2*k+1];
56+
}
57+
fft( ve, n/2, v ); /* FFT on even-indexed elements of v[] */
58+
fft( vo, n/2, v ); /* FFT on odd-indexed elements of v[] */
59+
for(m=0; m<n/2; m++) {
60+
w.Re = cos(2*PI*m/(double)n);
61+
w.Im = -sin(2*PI*m/(double)n);
62+
z.Re = w.Re*vo[m].Re - w.Im*vo[m].Im; /* Re(w*vo[m]) */
63+
z.Im = w.Re*vo[m].Im + w.Im*vo[m].Re; /* Im(w*vo[m]) */
64+
v[ m ].Re = ve[m].Re + z.Re;
65+
v[ m ].Im = ve[m].Im + z.Im;
66+
v[m+n/2].Re = ve[m].Re - z.Re;
67+
v[m+n/2].Im = ve[m].Im - z.Im;
68+
}
69+
}
70+
return;
71+
}
72+
73+
/*
74+
ifft(v,N):
75+
[0] If N==1 then return.
76+
[1] For k = 0 to N/2-1, let ve[k] = v[2*k]
77+
[2] Compute ifft(ve, N/2);
78+
[3] For k = 0 to N/2-1, let vo[k] = v[2*k+1]
79+
[4] Compute ifft(vo, N/2);
80+
[5] For m = 0 to N/2-1, do [6] through [9]
81+
[6] Let w.re = cos(2*PI*m/N)
82+
[7] Let w.im = sin(2*PI*m/N)
83+
[8] Let v[m] = ve[m] + w*vo[m]
84+
[9] Let v[m+N/2] = ve[m] - w*vo[m]
85+
*/
86+
void ifft( complex *v, int n, complex *tmp ) {
87+
88+
if(n>1) { /* otherwise, do nothing and return */
89+
int k,m; complex z, w, *vo, *ve;
90+
ve = tmp; vo = tmp+n/2;
91+
for(k=0; k<n/2; k++) {
92+
ve[k] = v[2*k];
93+
vo[k] = v[2*k+1];
94+
}
95+
ifft( ve, n/2, v ); /* FFT on even-indexed elements of v[] */
96+
ifft( vo, n/2, v ); /* FFT on odd-indexed elements of v[] */
97+
for(m=0; m<n/2; m++) {
98+
w.Re = cos(2*PI*m/(double)n);
99+
w.Im = sin(2*PI*m/(double)n);
100+
z.Re = w.Re*vo[m].Re - w.Im*vo[m].Im; /* Re(w*vo[m]) */
101+
z.Im = w.Re*vo[m].Im + w.Im*vo[m].Re; /* Im(w*vo[m]) */
102+
v[ m ].Re = ve[m].Re + z.Re;
103+
v[ m ].Im = ve[m].Im + z.Im;
104+
v[m+n/2].Re = ve[m].Re - z.Re;
105+
v[m+n/2].Im = ve[m].Im - z.Im;
106+
}
107+
}
108+
return;
109+
}
110+
111+
int main(void) {
112+
113+
complex v[N], v1[N], scratch[N];
114+
int k;
115+
116+
for (int x=0; x<10000; x++) {
117+
/* Fill v[] with a function of known FFT: */
118+
for(k=0; k<N; k++) {
119+
v[k].Re = 0.125 * cos(2*PI*k/(double)N);
120+
v[k].Im = 0.125 * sin(2*PI*k/(double)N);
121+
v1[k].Re = 0.3 * cos(2*PI*k/(double)N);
122+
v1[k].Im = -0.3 * sin(2*PI*k/(double)N);
123+
}
124+
125+
/* FFT, iFFT of v[]: */
126+
print_vector("Orig", v, N);
127+
fft( v, N, scratch );
128+
print_vector(" FFT", v, N);
129+
ifft( v, N, scratch );
130+
print_vector("iFFT", v, N);
131+
132+
/* FFT, iFFT of v1[]: */
133+
print_vector("Orig", v1, N);
134+
fft( v1, N, scratch );
135+
print_vector(" FFT", v1, N);
136+
ifft( v1, N, scratch );
137+
print_vector("iFFT", v1, N);
138+
}
139+
140+
exit(EXIT_SUCCESS);
141+
}
142+

tests/hellofft/project.seer

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"seerproject": {
3+
"executable": "hellofft",
4+
"postgdbcommands": [
5+
""
6+
],
7+
"pregdbcommands": [
8+
""
9+
],
10+
"startmode": {
11+
"arguments": "",
12+
"breakinfunction": false,
13+
"breakinfunctionname": "",
14+
"breakinmain": true,
15+
"breakpointsfile": "",
16+
"nobreak": false,
17+
"nonstopmode": false,
18+
"randomizestartaddress": false,
19+
"showassemblytab": false
20+
},
21+
"symbolfile": "",
22+
"workingdirectory": ""
23+
}
24+
}

0 commit comments

Comments
 (0)