Поменял... Компиляция, построение успешны.
C++ | 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
| #include <stdio.h>
#include <././sys/stat.h>
#include <fcntl.h>
#include <streambuf>
#include <dirent.h>
#include <vector>
#include <string>
#include <cstdlib>
#include "Unit1.h"
bool bFind = false, bCsv = false, bFilter = false, bCDRHeader = false;
bool bCDRExchangeID = false, bCDR_SWversion = false, bCDR_FileName = false;
int iInterFieldSize = 0; // число байт между первыми полями A3
int bufPos = 0; // текущая позиция в буфере чтения из файла =0
int iFilePos = 0; // текущая позиция в файле =0
int findRecSize =0; // размер найденной записи
int iSpaceNumber = 0;
int iFoundRecordsNumber = 1; //, iCDRHeaderLength;
long int iFileSize =0;
//------------- ф-ция нахождения длины строки ------------------
int find_length(char* input)
{
int length;
__asm__ volatile (
//"leal $input, %edi \n\t"
//"movl $input, %eax \n\t"
//"leal 1(%eax), %edi \n\t"
"movl %1, %%eax \n\t"
"leal 1(%%eax), %%edi \n\t"
"xorl %%ecx, %%ecx \n\t"
"movl (%%edi), %%esi \n\t"
"nexch2: \n\t"
"movb (%%esi), %%al \n\t"
"incl %%esi \n\t"
"incl %%ecx \n\t" // длина
"testb %%al, %%al \n\t"
"jnz nexch2 \n\t"
"decl %%ecx \n\t" // длина найдена
//"leal $length, %edx \n\t"
//"movl $length, %eax \n\t"
//"leal 1(%eax), %edx \n\t"
"movl %0, %%eax \n\t"
"leal 1(%%eax), %%edx \n\t"
"movl %%ecx, (%%edx) \n\t"
: "=&d"(length) // output
: "D"(input) // input
: // modified
);
return length; // в eax
}
//------- ф-ция преобразования строки из 10-тичных цифр в целое число ---------
int char2int (char* input)
{
int output, ilength;
ilength = find_length(input);
__asm__ (
//"movl ($input), %edi \n\t"
//"movl ($ilength), %ecx \n\t"
"movl (%1), %%edi \n\t"
"movl (%2), %%ecx \n\t"
"xorl %%eax, %%eax \n\t"
"incl %%eax \n\t" // al =1
"xorl %%esi, %%esi \n\t" // esi =0 , [edi-ecx] = input
"addl %%ecx, %%edi \n\t"
"decl %%edi \n\t" // [edi] = last char in string input = "1048576"
"movb (%%edi), %%dl \n\t"
"andl $0x0f, %%edx \n\t" // edx = last char of input without fist semibyte of ASCII
"addl %%edx, %%esi \n\t" // esi = ------"---------"--------
"decl %%edi \n\t" // [edi] = next char begining from end of input
"decl %%ecx \n\t"
"begint: \n\t"
"movb (%%edi), %%bl \n\t"
"andl $0x0f, %%ebx \n\t" // ebx = next char begining from end of input without first semibyte
"imull $10, %%eax \n\t" // eax = eax * 10
"imull %%eax, %%ebx \n\t" // ebx = ebx * eax
"addl %%ebx, %%esi \n\t" // esi = esi + ebx * eax
"decl %%edi \n\t" // [edi] = next char begining from end of input
"decl %%ecx \n\t" // ecx = number of char in input begining from start
"jnz begint \n\t" // number != 0 ?
//"leal $output, %edx \n\t"
//"movl $output, %eax \n\t"
//"leal 1(%eax), %edi \n\t"
"movl %0, %%eax \n\t"
"leal 1(%%eax), %%edi \n\t"
"movl %%esi, (%%edx) \n\t"
: "=&d" (output) // output
: "D" (input), "c" (ilength) // input
: // modify
);
}
//------ ф-ция преобразования ASCII строки из цифр в TBCD строку ------
// например, ASCII код 32 36 35 38 30 33 = TBCD код 26 58 03
void char2tbcd(char* input, int &ilength, void *SubNBuf)
{
ilength = find_length(input);
__asm__ volatile (
//"movl $ilength, %eax \n\t"
//"movl (%eax), %ecx \n\t"
"movl %1, %%eax \n\t"
"movl (%%eax), %%ecx \n\t"
//"movl $input, %eax \n\t"
"movl %2, %%eax \n\t"
//"movl $SubNBuf, %edi \n\t"
"movl %0, %%edi \n\t"
"xorl %%ebx, %%ebx \n\t"
"begin1: \n\t"
"movb (%%eax), %%bl \n\t"
"shlb $4, %%bl \n\t"
"movb (%%eax,1), %%bh \n\t"
"andb $0x0f, %%bh \n\t"
"orb %%bh, %%bl \n\t"
"movb %%bl, (%%edi) \n\t"
"incl %%eax \n\t"
"incl %%eax \n\t"
"incl %%edi \n\t"
"decl %%ecx \n\t"
"decl %%ecx \n\t"
"jnle begin1 \n\t" // если не меньше или равно 0, т.е. > =0
: "=&D" (SubNBuf) // output
: "a" (ilength), "c" (input) // input
: // modify
);
if(ilength>0) {
ilength = ilength+1;
ilength = ilength-1;
}
}
//------------------- функция сравнение строки с шаблоном -------------------
int wildcmp(const char *wild, const char *string)
{
const char *cp, *mp;
while ((*string) && (*wild != '*')) {
if ((*wild != *string) && (*wild != '?')) return 0;
wild++;
string++;
}
while (*string) {
if (*wild == '*') {
if (!*++wild) return 1;
mp = wild;
cp = string+1;
}
else if ((*wild == *string) || (*wild == '?')) {
wild++;
string++;
}
else {
wild = mp;
string = cp++;
}
}
while (*wild == '*') wild++;
return !*wild;
}
//-------------------------- ГЛАВНАЯ ФУНКЦИЯ ---------------------------------
int main(int argc, char* argv[])
{
int handle, handle2, bytes, iTBCDlen, iLength;
int ic_blength, ic_Nlength;
void *xNsubsc, *xNsubsc2;
char cTimebuf[32]; // для показа времени
long iTimeValue; // для показа времени
int recordsize = 0x100; // размер find_rec_buf =256 байт для найденной записи
bool bOdd; // признак нечетного номера - другой способ поиска
bool bNsub, bAsub;
bool bMultyFiles = false, bFileNamesMatch = false;
char *arg, *cbufsize = "1048576", *cSubsc, *cNsubsc, *cOddEven;
char *sTime = " ";
char *cInputFileName ="11111111111111111111111111111111111111\
11111111111111111111111111111111111111\
11111111111111111111111111111111111111\
11111111111111111111111111111111111111";
struct stat statbuf;
int bufsize=0;
void *buf; // буфер для файла размером bufsize
char *path = NULL;
size_t size;
DIR *dir;
struct dirent *ent;
using namespace std;
vector<string> FileNameList;
if(argc==1) {
printf( //ShowHelp:
"Q.825 CDR decoder and filter program, version 2.3 (build 40)\n\
Usage:\n\n\
cdrdec -f inputfile arguments > outputfile\n\n");
return 1;
}
printf("Input parameters are:\n");
for(int i=1;i<argc;i++) { // цикл введенных параметров
arg = argv[i];
if(arg[0]=='-') { // если начинается на '-'
switch (arg[1]) {
case 'f':
cInputFileName = argv[i+1];
iLength = find_length(cInputFileName);
// поиск и подсчет символа * внутри строки
__asm__ volatile (
"movb $'*', %%al \n\t" // 0x2A
"xorl %%ecx, %%ecx \n\t"
//"movl ($cInputFileName), %edi \n\t"
"movl (%1), %%edi \n\t"
"ScasbInputFileName: \n\t"
"incl %%ecx \n\t" // счетчик символов внутри cInputFileName
"scasb \n\t"
"jz SymbolFound \n\t"
"cmpb $0, (%%edi) \n\t"
"jz EndSearchSymbolInFileName \n\t"
"jmp ScasbInputFileName \n\t"
"SymbolFound: \n\t"
//"movb $1, $bMultyFiles \n\t"
//"movl $bMultyFiles, %eax \n\t"
//"movl %0, %%eax \n\t"
//"movb $1, (%%eax) \n\t"
"movb $1, %0 \n\t"
"movl %%ecx, %%ebx \n\t" // сохраним позицию '*' внутри cInputFileName
"EndSearchSymbolInFileName: \n\t" // ecx - позиция '*' внутри cInputFileName
: "=&a" (bMultyFiles) // output
: "D" (cInputFileName) // input
:
);
if(bMultyFiles) { // если много входных файлов
path = getcwd(path, size);
if ((dir = opendir(path)) == NULL) {
perror("Unable to open directory");
exit(1);
}
printf(" input files:\n");
while ((ent = readdir(dir)) != NULL) {
if(wildcmp(cInputFileName, ent->d_name)) {
printf(" %s\n",ent->d_name);
FileNameList.insert(FileNameList.end(),ent->d_name);
bFileNamesMatch = 1;
}
}
if(!bFileNamesMatch) {
printf(" no match.\n");
return 1;
}
if (closedir(dir) != 0) {
perror("Unable to close directory");
return 1;
}
}
else // если один входной файл
if ((handle = open(cInputFileName, O_RDONLY)) != -1) {
printf(" input file - %s\n", cInputFileName);
FileNameList.insert(FileNameList.end(),cInputFileName);
}
else {
perror("open input file failed, error");
return 1;
}
break;
case 'o':
handle2 = open(argv[i+1], O_CREAT |O_APPEND);
if (handle2 != -1) { // argv[i+1] - выходной файл
printf(" output file - %s\n", argv[i+1]);
}
else {
perror("create output file failed, error");
return 1;
}
break;
case 'b':
cbufsize = argv[i+1]; // argv[i+1] - размер буфера
break;
case 'A': // фильтр поиска аб-та А
bFilter = 1;
cSubsc = "A";
bAsub = true;
bNsub = false;
cNsubsc = argv[i+1];
break;
case 'B': // фильтр поиска аб-та Б
bFilter = 1;
cSubsc = "B";
bAsub = false;
bNsub = false;
cNsubsc = argv[i+1];
break;
case 'N': // фильтр поиска номера любого аб-та
bFilter = 1;
cSubsc = "N";
bAsub = false;
bNsub = true;
cNsubsc = argv[i+1];
break;
case 'c':
bCsv = true;
break;
} // конец если начинается на '-'
} // конец switch
} // конец цикла
} |
|
Только при пошаговом исполнении после 230 строки, где стоит Breakpoint, Codelite сразу переходит на 50, т.е.
по ассемблерным вставкам он не проходит. Другого графического debugger-а у меня нет. Но дело в том, что при запуске с параметрами -f filename* в терминале выходит "Input parameters are:
Segmentation fault", что значит, вероятно, программа скомпилирована без ассемблерных вставок. Или ошибка в другом, но проследить ее я не могу, т.к. Codelite после 50 строки выдает MessageBox
"Program Received signal SIGDEV
Stack trace is available in the Call Stack tab"
Вот данные из Call Stack tab:
Bash | 1
2
| 0 0x08048a59 find_length /home/avatar/projects/codelite/InsertToCsvString/InsertToCsvString.cpp 50
1 0x08048d21 main /home/avatar/projects/codelite/InsertToCsvString/InsertToCsvString.cpp 230 |
|
Вот лог debugger-а после MessageBox:
Bash | 1
2
3
4
5
6
7
8
9
10
11
| DEBUG>>*stopped,reason="exited-signalled",signal-name="SIGSEGV",signal-meaning="Segmentation fault"
DEBUG>>00000571-file-list-exec-source-file
DEBUG>>00000572-break-list
DEBUG>>00000571^done,line="50",file="/home/avatar/projects/codelite/InsertToCsvString/InsertToCsvString.cpp",fullname="/home/avatar/projects/codelite/InsertToCsvString/InsertToCsvString.cpp",macro-info="0"
DEBUG>>00000573-stack-list-frames
DEBUG>>00000572^done,BreakpointTable={nr_rows="3",nr_cols="6",hdr=[{width="7",alignment="-1",col_name="number",colhdr="Num"},{width="14",alignment="-1",col_name="type",colhdr="Type"},{width="4",alignment="-1",col_name="disp",colhdr="Disp"},{width="3",alignment="-1",col_name="enabled",colhdr="Enb"},{width="10",alignment="-1",col_name="addr",colhdr="Address"},{width="40",alignment="2",col_name="what",colhdr="What"}],body=[bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x08048d16",func="main",file="/home/avatar/projects/codelite/InsertToCsvString/InsertToCsvString.cpp",fullname="/home/avatar/projects/codelite/InsertToCsvString/InsertToCsvString.cpp",line="230",times="1",original-location="\"/home/avatar/projects/codelite/InsertToCsvString/InsertToCsvString.cpp:230"},bkpt={number="2",type="breakpoint",disp="keep",enabled="y",addr="0x08048c50",func="main",file="/home/avatar/projects/codelite/InsertToCsvString/InsertToCsvString.cpp",fullname="/home/avatar/projects/codelite/InsertToCsvString/InsertToCsvString.cpp",line="188",times="1",original-location="\"/home/avatar/projects/codelite/InsertToCsvString/InsertToCsvString.cpp:188"},bkpt={number="3",type="breakpoint",disp="keep",enabled="y",addr="0x08048c50",func="main",file="/home/avatar/projects/codelite/InsertToCsvString/InsertToCsvString.cpp",fullname="/home/avatar/projects/codelite/InsertToCsvString/InsertToCsvString.cpp",line="188",times="1",original-location="main"}]}
DEBUG>>00000573^error,msg="No registers."
No registers.
DEBUG>>00000574-exec-step
DEBUG>>00000574^error,msg="The program is not being run."
The program is not being run. |
|
Ничего пока не ясно. Буду думать.
Добавлено через 3 минуты
Поменял... Компиляция, построение успешны.
C++ | 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
| #include <stdio.h>
#include <././sys/stat.h>
#include <fcntl.h>
#include <streambuf>
#include <dirent.h>
#include <vector>
#include <string>
#include <cstdlib>
#include "Unit1.h"
bool bFind = false, bCsv = false, bFilter = false, bCDRHeader = false;
bool bCDRExchangeID = false, bCDR_SWversion = false, bCDR_FileName = false;
int iInterFieldSize = 0; // число байт между первыми полями A3
int bufPos = 0; // текущая позиция в буфере чтения из файла =0
int iFilePos = 0; // текущая позиция в файле =0
int findRecSize =0; // размер найденной записи
int iSpaceNumber = 0;
int iFoundRecordsNumber = 1; //, iCDRHeaderLength;
long int iFileSize =0;
//------------- ф-ция нахождения длины строки ------------------
int find_length(char* input)
{
int length;
__asm__ volatile (
//"leal $input, %edi \n\t"
//"movl $input, %eax \n\t"
//"leal 1(%eax), %edi \n\t"
"movl %1, %%eax \n\t"
"leal 1(%%eax), %%edi \n\t"
"xorl %%ecx, %%ecx \n\t"
"movl (%%edi), %%esi \n\t"
"nexch2: \n\t"
"movb (%%esi), %%al \n\t"
"incl %%esi \n\t"
"incl %%ecx \n\t" // длина
"testb %%al, %%al \n\t"
"jnz nexch2 \n\t"
"decl %%ecx \n\t" // длина найдена
//"leal $length, %edx \n\t"
//"movl $length, %eax \n\t"
//"leal 1(%eax), %edx \n\t"
"movl %0, %%eax \n\t"
"leal 1(%%eax), %%edx \n\t"
"movl %%ecx, (%%edx) \n\t"
: "=&d"(length) // output
: "D"(input) // input
: // modified
);
return length; // в eax
}
//------- ф-ция преобразования строки из 10-тичных цифр в целое число ---------
int char2int (char* input)
{
int output, ilength;
ilength = find_length(input);
__asm__ (
//"movl ($input), %edi \n\t"
//"movl ($ilength), %ecx \n\t"
"movl (%1), %%edi \n\t"
"movl (%2), %%ecx \n\t"
"xorl %%eax, %%eax \n\t"
"incl %%eax \n\t" // al =1
"xorl %%esi, %%esi \n\t" // esi =0 , [edi-ecx] = input
"addl %%ecx, %%edi \n\t"
"decl %%edi \n\t" // [edi] = last char in string input = "1048576"
"movb (%%edi), %%dl \n\t"
"andl $0x0f, %%edx \n\t" // edx = last char of input without fist semibyte of ASCII
"addl %%edx, %%esi \n\t" // esi = ------"---------"--------
"decl %%edi \n\t" // [edi] = next char begining from end of input
"decl %%ecx \n\t"
"begint: \n\t"
"movb (%%edi), %%bl \n\t"
"andl $0x0f, %%ebx \n\t" // ebx = next char begining from end of input without first semibyte
"imull $10, %%eax \n\t" // eax = eax * 10
"imull %%eax, %%ebx \n\t" // ebx = ebx * eax
"addl %%ebx, %%esi \n\t" // esi = esi + ebx * eax
"decl %%edi \n\t" // [edi] = next char begining from end of input
"decl %%ecx \n\t" // ecx = number of char in input begining from start
"jnz begint \n\t" // number != 0 ?
//"leal $output, %edx \n\t"
//"movl $output, %eax \n\t"
//"leal 1(%eax), %edi \n\t"
"movl %0, %%eax \n\t"
"leal 1(%%eax), %%edi \n\t"
"movl %%esi, (%%edx) \n\t"
: "=&d" (output) // output
: "D" (input), "c" (ilength) // input
: // modify
);
}
//------ ф-ция преобразования ASCII строки из цифр в TBCD строку ------
// например, ASCII код 32 36 35 38 30 33 = TBCD код 26 58 03
void char2tbcd(char* input, int &ilength, void *SubNBuf)
{
ilength = find_length(input);
__asm__ volatile (
//"movl $ilength, %eax \n\t"
//"movl (%eax), %ecx \n\t"
"movl %1, %%eax \n\t"
"movl (%%eax), %%ecx \n\t"
//"movl $input, %eax \n\t"
"movl %2, %%eax \n\t"
//"movl $SubNBuf, %edi \n\t"
"movl %0, %%edi \n\t"
"xorl %%ebx, %%ebx \n\t"
"begin1: \n\t"
"movb (%%eax), %%bl \n\t"
"shlb $4, %%bl \n\t"
"movb (%%eax,1), %%bh \n\t"
"andb $0x0f, %%bh \n\t"
"orb %%bh, %%bl \n\t"
"movb %%bl, (%%edi) \n\t"
"incl %%eax \n\t"
"incl %%eax \n\t"
"incl %%edi \n\t"
"decl %%ecx \n\t"
"decl %%ecx \n\t"
"jnle begin1 \n\t" // если не меньше или равно 0, т.е. > =0
: "=&D" (SubNBuf) // output
: "a" (ilength), "c" (input) // input
: // modify
);
if(ilength>0) {
ilength = ilength+1;
ilength = ilength-1;
}
}
//------------------- функция сравнение строки с шаблоном -------------------
int wildcmp(const char *wild, const char *string)
{
const char *cp, *mp;
while ((*string) && (*wild != '*')) {
if ((*wild != *string) && (*wild != '?')) return 0;
wild++;
string++;
}
while (*string) {
if (*wild == '*') {
if (!*++wild) return 1;
mp = wild;
cp = string+1;
}
else if ((*wild == *string) || (*wild == '?')) {
wild++;
string++;
}
else {
wild = mp;
string = cp++;
}
}
while (*wild == '*') wild++;
return !*wild;
}
//-------------------------- ГЛАВНАЯ ФУНКЦИЯ ---------------------------------
int main(int argc, char* argv[])
{
int handle, handle2, bytes, iTBCDlen, iLength;
int ic_blength, ic_Nlength;
void *xNsubsc, *xNsubsc2;
char cTimebuf[32]; // для показа времени
long iTimeValue; // для показа времени
int recordsize = 0x100; // размер find_rec_buf =256 байт для найденной записи
bool bOdd; // признак нечетного номера - другой способ поиска
bool bNsub, bAsub;
bool bMultyFiles = false, bFileNamesMatch = false;
char *arg, *cbufsize = "1048576", *cSubsc, *cNsubsc, *cOddEven;
char *sTime = " ";
char *cInputFileName ="11111111111111111111111111111111111111\
11111111111111111111111111111111111111\
11111111111111111111111111111111111111\
11111111111111111111111111111111111111";
struct stat statbuf;
int bufsize=0;
void *buf; // буфер для файла размером bufsize
char *path = NULL;
size_t size;
DIR *dir;
struct dirent *ent;
using namespace std;
vector<string> FileNameList;
if(argc==1) {
printf( //ShowHelp:
"Q.825 CDR decoder and filter program, version 2.3 (build 40)\n\
Usage:\n\n\
cdrdec -f inputfile arguments > outputfile\n\n");
return 1;
}
printf("Input parameters are:\n");
for(int i=1;i<argc;i++) { // цикл введенных параметров
arg = argv[i];
if(arg[0]=='-') { // если начинается на '-'
switch (arg[1]) {
case 'f':
cInputFileName = argv[i+1];
iLength = find_length(cInputFileName);
// поиск и подсчет символа * внутри строки
__asm__ volatile (
"movb $'*', %%al \n\t" // 0x2A
"xorl %%ecx, %%ecx \n\t"
//"movl ($cInputFileName), %edi \n\t"
"movl (%1), %%edi \n\t"
"ScasbInputFileName: \n\t"
"incl %%ecx \n\t" // счетчик символов внутри cInputFileName
"scasb \n\t"
"jz SymbolFound \n\t"
"cmpb $0, (%%edi) \n\t"
"jz EndSearchSymbolInFileName \n\t"
"jmp ScasbInputFileName \n\t"
"SymbolFound: \n\t"
//"movb $1, $bMultyFiles \n\t"
//"movl $bMultyFiles, %eax \n\t"
//"movl %0, %%eax \n\t"
//"movb $1, (%%eax) \n\t"
"movb $1, %0 \n\t"
"movl %%ecx, %%ebx \n\t" // сохраним позицию '*' внутри cInputFileName
"EndSearchSymbolInFileName: \n\t" // ecx - позиция '*' внутри cInputFileName
: "=&a" (bMultyFiles) // output
: "D" (cInputFileName) // input
:
);
if(bMultyFiles) { // если много входных файлов
path = getcwd(path, size);
if ((dir = opendir(path)) == NULL) {
perror("Unable to open directory");
exit(1);
}
printf(" input files:\n");
while ((ent = readdir(dir)) != NULL) {
if(wildcmp(cInputFileName, ent->d_name)) {
printf(" %s\n",ent->d_name);
FileNameList.insert(FileNameList.end(),ent->d_name);
bFileNamesMatch = 1;
}
}
if(!bFileNamesMatch) {
printf(" no match.\n");
return 1;
}
if (closedir(dir) != 0) {
perror("Unable to close directory");
return 1;
}
}
else // если один входной файл
if ((handle = open(cInputFileName, O_RDONLY)) != -1) {
printf(" input file - %s\n", cInputFileName);
FileNameList.insert(FileNameList.end(),cInputFileName);
}
else {
perror("open input file failed, error");
return 1;
}
break;
case 'o':
handle2 = open(argv[i+1], O_CREAT |O_APPEND);
if (handle2 != -1) { // argv[i+1] - выходной файл
printf(" output file - %s\n", argv[i+1]);
}
else {
perror("create output file failed, error");
return 1;
}
break;
case 'b':
cbufsize = argv[i+1]; // argv[i+1] - размер буфера
break;
case 'A': // фильтр поиска аб-та А
bFilter = 1;
cSubsc = "A";
bAsub = true;
bNsub = false;
cNsubsc = argv[i+1];
break;
case 'B': // фильтр поиска аб-та Б
bFilter = 1;
cSubsc = "B";
bAsub = false;
bNsub = false;
cNsubsc = argv[i+1];
break;
case 'N': // фильтр поиска номера любого аб-та
bFilter = 1;
cSubsc = "N";
bAsub = false;
bNsub = true;
cNsubsc = argv[i+1];
break;
case 'c':
bCsv = true;
break;
} // конец если начинается на '-'
} // конец switch
} // конец цикла
} |
|
Без параметров работает.
При запуске с параметрами -f filename* в терминале выходит "Input parameters are:
Segmentation fault", что значит, вероятно, программа скомпилирована без ассемблерных вставок. Или ошибка в другом, но проследить ее я не могу.
При пошаговом исполнении с параметрами -f filename* после 230 строки, где стоит Breakpoint, Codelite сразу переходит на 50, т.е.
по ассемблерным вставкам он не проходит. Другого графического debugger-а у меня нет, Codelite после 50 строки выдает MessageBox:
Bash | 1
2
| "Program Received signal SIGDEV
Stack trace is available in the Call Stack tab" |
|
Вот данные из Call Stack tab:
Bash | 1
2
| 0 0x08048a59 find_length /home/avatar/projects/codelite/InsertToCsvString/InsertToCsvString.cpp 50
1 0x08048d21 main /home/avatar/projects/codelite/InsertToCsvString/InsertToCsvString.cpp 230 |
|
Вот лог debugger-а после MessageBox:
Bash | 1
2
3
4
5
6
7
8
9
10
11
| DEBUG>>*stopped,reason="exited-signalled",signal-name="SIGSEGV",signal-meaning="Segmentation fault"
DEBUG>>00000571-file-list-exec-source-file
DEBUG>>00000572-break-list
DEBUG>>00000571^done,line="50",file="/home/avatar/projects/codelite/InsertToCsvString/InsertToCsvString.cpp",fullname="/home/avatar/projects/codelite/InsertToCsvString/InsertToCsvString.cpp",macro-info="0"
DEBUG>>00000573-stack-list-frames
DEBUG>>00000572^done,BreakpointTable={nr_rows="3",nr_cols="6",hdr=[{width="7",alignment="-1",col_name="number",colhdr="Num"},{width="14",alignment="-1",col_name="type",colhdr="Type"},{width="4",alignment="-1",col_name="disp",colhdr="Disp"},{width="3",alignment="-1",col_name="enabled",colhdr="Enb"},{width="10",alignment="-1",col_name="addr",colhdr="Address"},{width="40",alignment="2",col_name="what",colhdr="What"}],body=[bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x08048d16",func="main",file="/home/avatar/projects/codelite/InsertToCsvString/InsertToCsvString.cpp",fullname="/home/avatar/projects/codelite/InsertToCsvString/InsertToCsvString.cpp",line="230",times="1",original-location="\"/home/avatar/projects/codelite/InsertToCsvString/InsertToCsvString.cpp:230"},bkpt={number="2",type="breakpoint",disp="keep",enabled="y",addr="0x08048c50",func="main",file="/home/avatar/projects/codelite/InsertToCsvString/InsertToCsvString.cpp",fullname="/home/avatar/projects/codelite/InsertToCsvString/InsertToCsvString.cpp",line="188",times="1",original-location="\"/home/avatar/projects/codelite/InsertToCsvString/InsertToCsvString.cpp:188"},bkpt={number="3",type="breakpoint",disp="keep",enabled="y",addr="0x08048c50",func="main",file="/home/avatar/projects/codelite/InsertToCsvString/InsertToCsvString.cpp",fullname="/home/avatar/projects/codelite/InsertToCsvString/InsertToCsvString.cpp",line="188",times="1",original-location="main"}]}
DEBUG>>00000573^error,msg="No registers."
No registers.
DEBUG>>00000574-exec-step
DEBUG>>00000574^error,msg="The program is not being run."
The program is not being run. |
|
Пока не ясно, копимлируются ассемблерные вставки или нет, скорее нет. Буду думать.
Добавлено через 33 секунды
Поменял... Компиляция, построение успешны.
C++ | 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
| #include <stdio.h>
#include <././sys/stat.h>
#include <fcntl.h>
#include <streambuf>
#include <dirent.h>
#include <vector>
#include <string>
#include <cstdlib>
#include "Unit1.h"
bool bFind = false, bCsv = false, bFilter = false, bCDRHeader = false;
bool bCDRExchangeID = false, bCDR_SWversion = false, bCDR_FileName = false;
int iInterFieldSize = 0; // число байт между первыми полями A3
int bufPos = 0; // текущая позиция в буфере чтения из файла =0
int iFilePos = 0; // текущая позиция в файле =0
int findRecSize =0; // размер найденной записи
int iSpaceNumber = 0;
int iFoundRecordsNumber = 1; //, iCDRHeaderLength;
long int iFileSize =0;
//------------- ф-ция нахождения длины строки ------------------
int find_length(char* input)
{
int length;
__asm__ volatile (
//"leal $input, %edi \n\t"
//"movl $input, %eax \n\t"
//"leal 1(%eax), %edi \n\t"
"movl %1, %%eax \n\t"
"leal 1(%%eax), %%edi \n\t"
"xorl %%ecx, %%ecx \n\t"
"movl (%%edi), %%esi \n\t"
"nexch2: \n\t"
"movb (%%esi), %%al \n\t"
"incl %%esi \n\t"
"incl %%ecx \n\t" // длина
"testb %%al, %%al \n\t"
"jnz nexch2 \n\t"
"decl %%ecx \n\t" // длина найдена
//"leal $length, %edx \n\t"
//"movl $length, %eax \n\t"
//"leal 1(%eax), %edx \n\t"
"movl %0, %%eax \n\t"
"leal 1(%%eax), %%edx \n\t"
"movl %%ecx, (%%edx) \n\t"
: "=&d"(length) // output
: "D"(input) // input
: // modified
);
return length; // в eax
}
//------- ф-ция преобразования строки из 10-тичных цифр в целое число ---------
int char2int (char* input)
{
int output, ilength;
ilength = find_length(input);
__asm__ (
//"movl ($input), %edi \n\t"
//"movl ($ilength), %ecx \n\t"
"movl (%1), %%edi \n\t"
"movl (%2), %%ecx \n\t"
"xorl %%eax, %%eax \n\t"
"incl %%eax \n\t" // al =1
"xorl %%esi, %%esi \n\t" // esi =0 , [edi-ecx] = input
"addl %%ecx, %%edi \n\t"
"decl %%edi \n\t" // [edi] = last char in string input = "1048576"
"movb (%%edi), %%dl \n\t"
"andl $0x0f, %%edx \n\t" // edx = last char of input without fist semibyte of ASCII
"addl %%edx, %%esi \n\t" // esi = ------"---------"--------
"decl %%edi \n\t" // [edi] = next char begining from end of input
"decl %%ecx \n\t"
"begint: \n\t"
"movb (%%edi), %%bl \n\t"
"andl $0x0f, %%ebx \n\t" // ebx = next char begining from end of input without first semibyte
"imull $10, %%eax \n\t" // eax = eax * 10
"imull %%eax, %%ebx \n\t" // ebx = ebx * eax
"addl %%ebx, %%esi \n\t" // esi = esi + ebx * eax
"decl %%edi \n\t" // [edi] = next char begining from end of input
"decl %%ecx \n\t" // ecx = number of char in input begining from start
"jnz begint \n\t" // number != 0 ?
//"leal $output, %edx \n\t"
//"movl $output, %eax \n\t"
//"leal 1(%eax), %edi \n\t"
"movl %0, %%eax \n\t"
"leal 1(%%eax), %%edi \n\t"
"movl %%esi, (%%edx) \n\t"
: "=&d" (output) // output
: "D" (input), "c" (ilength) // input
: // modify
);
}
//------ ф-ция преобразования ASCII строки из цифр в TBCD строку ------
// например, ASCII код 32 36 35 38 30 33 = TBCD код 26 58 03
void char2tbcd(char* input, int &ilength, void *SubNBuf)
{
ilength = find_length(input);
__asm__ volatile (
//"movl $ilength, %eax \n\t"
//"movl (%eax), %ecx \n\t"
"movl %1, %%eax \n\t"
"movl (%%eax), %%ecx \n\t"
//"movl $input, %eax \n\t"
"movl %2, %%eax \n\t"
//"movl $SubNBuf, %edi \n\t"
"movl %0, %%edi \n\t"
"xorl %%ebx, %%ebx \n\t"
"begin1: \n\t"
"movb (%%eax), %%bl \n\t"
"shlb $4, %%bl \n\t"
"movb (%%eax,1), %%bh \n\t"
"andb $0x0f, %%bh \n\t"
"orb %%bh, %%bl \n\t"
"movb %%bl, (%%edi) \n\t"
"incl %%eax \n\t"
"incl %%eax \n\t"
"incl %%edi \n\t"
"decl %%ecx \n\t"
"decl %%ecx \n\t"
"jnle begin1 \n\t" // если не меньше или равно 0, т.е. > =0
: "=&D" (SubNBuf) // output
: "a" (ilength), "c" (input) // input
: // modify
);
if(ilength>0) {
ilength = ilength+1;
ilength = ilength-1;
}
}
//------------------- функция сравнение строки с шаблоном -------------------
int wildcmp(const char *wild, const char *string)
{
const char *cp, *mp;
while ((*string) && (*wild != '*')) {
if ((*wild != *string) && (*wild != '?')) return 0;
wild++;
string++;
}
while (*string) {
if (*wild == '*') {
if (!*++wild) return 1;
mp = wild;
cp = string+1;
}
else if ((*wild == *string) || (*wild == '?')) {
wild++;
string++;
}
else {
wild = mp;
string = cp++;
}
}
while (*wild == '*') wild++;
return !*wild;
}
//-------------------------- ГЛАВНАЯ ФУНКЦИЯ ---------------------------------
int main(int argc, char* argv[])
{
int handle, handle2, bytes, iTBCDlen, iLength;
int ic_blength, ic_Nlength;
void *xNsubsc, *xNsubsc2;
char cTimebuf[32]; // для показа времени
long iTimeValue; // для показа времени
int recordsize = 0x100; // размер find_rec_buf =256 байт для найденной записи
bool bOdd; // признак нечетного номера - другой способ поиска
bool bNsub, bAsub;
bool bMultyFiles = false, bFileNamesMatch = false;
char *arg, *cbufsize = "1048576", *cSubsc, *cNsubsc, *cOddEven;
char *sTime = " ";
char *cInputFileName ="11111111111111111111111111111111111111\
11111111111111111111111111111111111111\
11111111111111111111111111111111111111\
11111111111111111111111111111111111111";
struct stat statbuf;
int bufsize=0;
void *buf; // буфер для файла размером bufsize
char *path = NULL;
size_t size;
DIR *dir;
struct dirent *ent;
using namespace std;
vector<string> FileNameList;
if(argc==1) {
printf( //ShowHelp:
"Q.825 CDR decoder and filter program, version 2.3 (build 40)\n\
Usage:\n\n\
cdrdec -f inputfile arguments > outputfile\n\n");
return 1;
}
printf("Input parameters are:\n");
for(int i=1;i<argc;i++) { // цикл введенных параметров
arg = argv[i];
if(arg[0]=='-') { // если начинается на '-'
switch (arg[1]) {
case 'f':
cInputFileName = argv[i+1];
iLength = find_length(cInputFileName);
// поиск и подсчет символа * внутри строки
__asm__ volatile (
"movb $'*', %%al \n\t" // 0x2A
"xorl %%ecx, %%ecx \n\t"
//"movl ($cInputFileName), %edi \n\t"
"movl (%1), %%edi \n\t"
"ScasbInputFileName: \n\t"
"incl %%ecx \n\t" // счетчик символов внутри cInputFileName
"scasb \n\t"
"jz SymbolFound \n\t"
"cmpb $0, (%%edi) \n\t"
"jz EndSearchSymbolInFileName \n\t"
"jmp ScasbInputFileName \n\t"
"SymbolFound: \n\t"
//"movb $1, $bMultyFiles \n\t"
//"movl $bMultyFiles, %eax \n\t"
//"movl %0, %%eax \n\t"
//"movb $1, (%%eax) \n\t"
"movb $1, %0 \n\t"
"movl %%ecx, %%ebx \n\t" // сохраним позицию '*' внутри cInputFileName
"EndSearchSymbolInFileName: \n\t" // ecx - позиция '*' внутри cInputFileName
: "=&a" (bMultyFiles) // output
: "D" (cInputFileName) // input
:
);
if(bMultyFiles) { // если много входных файлов
path = getcwd(path, size);
if ((dir = opendir(path)) == NULL) {
perror("Unable to open directory");
exit(1);
}
printf(" input files:\n");
while ((ent = readdir(dir)) != NULL) {
if(wildcmp(cInputFileName, ent->d_name)) {
printf(" %s\n",ent->d_name);
FileNameList.insert(FileNameList.end(),ent->d_name);
bFileNamesMatch = 1;
}
}
if(!bFileNamesMatch) {
printf(" no match.\n");
return 1;
}
if (closedir(dir) != 0) {
perror("Unable to close directory");
return 1;
}
}
else // если один входной файл
if ((handle = open(cInputFileName, O_RDONLY)) != -1) {
printf(" input file - %s\n", cInputFileName);
FileNameList.insert(FileNameList.end(),cInputFileName);
}
else {
perror("open input file failed, error");
return 1;
}
break;
case 'o':
handle2 = open(argv[i+1], O_CREAT |O_APPEND);
if (handle2 != -1) { // argv[i+1] - выходной файл
printf(" output file - %s\n", argv[i+1]);
}
else {
perror("create output file failed, error");
return 1;
}
break;
case 'b':
cbufsize = argv[i+1]; // argv[i+1] - размер буфера
break;
case 'A': // фильтр поиска аб-та А
bFilter = 1;
cSubsc = "A";
bAsub = true;
bNsub = false;
cNsubsc = argv[i+1];
break;
case 'B': // фильтр поиска аб-та Б
bFilter = 1;
cSubsc = "B";
bAsub = false;
bNsub = false;
cNsubsc = argv[i+1];
break;
case 'N': // фильтр поиска номера любого аб-та
bFilter = 1;
cSubsc = "N";
bAsub = false;
bNsub = true;
cNsubsc = argv[i+1];
break;
case 'c':
bCsv = true;
break;
} // конец если начинается на '-'
} // конец switch
} // конец цикла
} |
|
Без параметров работает.
При запуске с параметрами -f filename* в терминале выходит "Input parameters are:
Segmentation fault", что значит, вероятно, программа скомпилирована без ассемблерных вставок. Или ошибка в другом, но проследить ее я не могу.
При пошаговом исполнении с параметрами -f filename* после 230 строки, где стоит Breakpoint, Codelite сразу переходит на 50, т.е.
по ассемблерным вставкам он не проходит. Другого графического debugger-а у меня нет, Codelite после 50 строки выдает MessageBox:
Bash | 1
2
| "Program Received signal SIGDEV
Stack trace is available in the Call Stack tab" |
|
Вот данные из Call Stack tab:
Bash | 1
2
| 0 0x08048a59 find_length /home/avatar/projects/codelite/InsertToCsvString/InsertToCsvString.cpp 50
1 0x08048d21 main /home/avatar/projects/codelite/InsertToCsvString/InsertToCsvString.cpp 230 |
|
Вот лог debugger-а после MessageBox:
Bash | 1
2
3
4
5
6
7
8
9
10
11
| DEBUG>>*stopped,reason="exited-signalled",signal-name="SIGSEGV",signal-meaning="Segmentation fault"
DEBUG>>00000571-file-list-exec-source-file
DEBUG>>00000572-break-list
DEBUG>>00000571^done,line="50",file="/home/avatar/projects/codelite/InsertToCsvString/InsertToCsvString.cpp",fullname="/home/avatar/projects/codelite/InsertToCsvString/InsertToCsvString.cpp",macro-info="0"
DEBUG>>00000573-stack-list-frames
DEBUG>>00000572^done,BreakpointTable={nr_rows="3",nr_cols="6",hdr=[{width="7",alignment="-1",col_name="number",colhdr="Num"},{width="14",alignment="-1",col_name="type",colhdr="Type"},{width="4",alignment="-1",col_name="disp",colhdr="Disp"},{width="3",alignment="-1",col_name="enabled",colhdr="Enb"},{width="10",alignment="-1",col_name="addr",colhdr="Address"},{width="40",alignment="2",col_name="what",colhdr="What"}],body=[bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x08048d16",func="main",file="/home/avatar/projects/codelite/InsertToCsvString/InsertToCsvString.cpp",fullname="/home/avatar/projects/codelite/InsertToCsvString/InsertToCsvString.cpp",line="230",times="1",original-location="\"/home/avatar/projects/codelite/InsertToCsvString/InsertToCsvString.cpp:230"},bkpt={number="2",type="breakpoint",disp="keep",enabled="y",addr="0x08048c50",func="main",file="/home/avatar/projects/codelite/InsertToCsvString/InsertToCsvString.cpp",fullname="/home/avatar/projects/codelite/InsertToCsvString/InsertToCsvString.cpp",line="188",times="1",original-location="\"/home/avatar/projects/codelite/InsertToCsvString/InsertToCsvString.cpp:188"},bkpt={number="3",type="breakpoint",disp="keep",enabled="y",addr="0x08048c50",func="main",file="/home/avatar/projects/codelite/InsertToCsvString/InsertToCsvString.cpp",fullname="/home/avatar/projects/codelite/InsertToCsvString/InsertToCsvString.cpp",line="188",times="1",original-location="main"}]}
DEBUG>>00000573^error,msg="No registers."
No registers.
DEBUG>>00000574-exec-step
DEBUG>>00000574^error,msg="The program is not being run."
The program is not being run. |
|
Пока не ясно, компилируются ассемблерные вставки или нет, скорее нет. Буду думать.
0
|