Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
6446 | GerdtR | 1 | #include "tok.h" |
2 | |||
3 | |||
4 | |||
5 | #define _DEBUG_ |
||
6 | |||
7 | |||
8 | |||
9 | #define MAXDBGS 1000 |
||
10 | |||
11 | #define MAXNUMSYM 500 |
||
12 | |||
13 | #define MAXLSTSTR 128 //максимальный размер строки листинга |
||
14 | |||
15 | |||
16 | |||
17 | void AddNameToTable(char *name); |
||
18 | |||
19 | void AddSymbolList(struct idrec *ptr); |
||
20 | |||
21 | int CreateDosDebug(); |
||
22 | |||
23 | int CreateW32Debug(); |
||
24 | |||
25 | void GeneratLst(); |
||
26 | |||
27 | |||
28 | |||
29 | unsigned int *dbgloc=NULL; //адресс точки |
||
30 | |||
31 | unsigned int *dbgnum; //номер строки |
||
32 | |||
33 | unsigned short *dbgmod; //номер файла |
||
34 | |||
35 | char **lststring; //строки исходного текста |
||
36 | |||
37 | unsigned char *lstflag=NULL; //флаги управления листингом |
||
38 | |||
39 | unsigned int *lstend; |
||
40 | |||
41 | |||
42 | |||
43 | unsigned int pdbg=0; /* number of post entrys */ |
||
44 | |||
45 | unsigned int pdbgmax=MAXDBGS; /* max number of post entrys */ |
||
46 | |||
47 | static unsigned int oline=0,omodule=0xFFFFFFFF; |
||
48 | |||
49 | unsigned int ooutptr=0xffffffff; |
||
50 | |||
51 | char lsttypedata=0; //тип данных для листинга, по умолчанию код |
||
52 | |||
53 | unsigned int outputcodestart=0; |
||
54 | |||
55 | |||
56 | |||
57 | struct D16START{ |
||
58 | |||
59 | unsigned long sign; //0 Signify & Version |
||
60 | |||
61 | unsigned long pol_size; //4 Name Pool Size (in bytes) |
||
62 | |||
63 | unsigned long numname; //8 Number of Names |
||
64 | |||
65 | unsigned long numtentr; //12 Number of Type Entries |
||
66 | |||
67 | unsigned long nummentr; //16 Number of Member Entries |
||
68 | |||
69 | unsigned long numsymbl; //20 Number of Symbols |
||
70 | |||
71 | unsigned long numgsymb; //24 Number of Global Symbols |
||
72 | |||
73 | unsigned long numsours; //28 Number of Source Modules |
||
74 | |||
75 | unsigned long numlsumb; //32 Number of Local Symbols |
||
76 | |||
77 | unsigned long numscop; //36 Number of Scopes |
||
78 | |||
79 | unsigned long numline; //40 Number of Line Number Entries |
||
80 | |||
81 | unsigned long numincl; //44 Number of Include Files |
||
82 | |||
83 | unsigned long numseg; //48 Number of Segments |
||
84 | |||
85 | unsigned long numcorrel; //52 Number of Correlation Entries |
||
86 | |||
87 | unsigned long imagesize; //56 Image Size |
||
88 | |||
89 | unsigned short data[2]; //60 Basic RTL String Segment Offset & Data Count |
||
90 | |||
91 | unsigned long casesensiv;//64 Case Sensivitive Link |
||
92 | |||
93 | unsigned long ucnovn; |
||
94 | |||
95 | //только для 128-байтового заголовка |
||
96 | |||
97 | unsigned long ucnovn1[6]; |
||
98 | |||
99 | unsigned long sizeblock; //размер между началом имен и концом заголовка |
||
100 | |||
101 | unsigned long ucnovn2[2]; |
||
102 | |||
103 | unsigned short fdebug; //Debug Flags |
||
104 | |||
105 | unsigned long reftsize; //Reference Information Table Size (in bytes) |
||
106 | |||
107 | unsigned long numnamesp; //Number of Namespace Entries |
||
108 | |||
109 | unsigned long numunamesp; //Number of Namespace Using Entries |
||
110 | |||
111 | unsigned long ucnovn3; |
||
112 | |||
113 | unsigned short ucnovn4; |
||
114 | |||
115 | //////////////////////////////// |
||
116 | |||
117 | }; |
||
118 | |||
119 | |||
120 | |||
121 | struct MODULE{ |
||
122 | |||
123 | unsigned long name; |
||
124 | |||
125 | unsigned char language; |
||
126 | |||
127 | unsigned char memmodel; |
||
128 | |||
129 | unsigned long symindex; |
||
130 | |||
131 | unsigned short symcount; |
||
132 | |||
133 | unsigned short sourindex; |
||
134 | |||
135 | unsigned short sourcount; |
||
136 | |||
137 | unsigned short corindex; |
||
138 | |||
139 | unsigned short corcount; |
||
140 | |||
141 | }; |
||
142 | |||
143 | |||
144 | |||
145 | typedef struct _SFT_ |
||
146 | |||
147 | { |
||
148 | |||
149 | unsigned long idx; |
||
150 | |||
151 | struct ftime time; |
||
152 | |||
153 | }SFT; |
||
154 | |||
155 | |||
156 | |||
157 | typedef struct _LT_ |
||
158 | |||
159 | { |
||
160 | |||
161 | unsigned short line; |
||
162 | |||
163 | unsigned short ofs; |
||
164 | |||
165 | }LT; |
||
166 | |||
167 | |||
168 | |||
169 | typedef struct _CT_ |
||
170 | |||
171 | { |
||
172 | |||
173 | unsigned short segidx; |
||
174 | |||
175 | unsigned short filidx; |
||
176 | |||
177 | unsigned long beg; |
||
178 | |||
179 | unsigned short count; |
||
180 | |||
181 | }CT; |
||
182 | |||
183 | |||
184 | |||
185 | static struct _SMB_ |
||
186 | |||
187 | { |
||
188 | |||
189 | unsigned long idxname; |
||
190 | |||
191 | unsigned long type; |
||
192 | |||
193 | unsigned short ofs; |
||
194 | |||
195 | unsigned short seg; |
||
196 | |||
197 | unsigned short clas; |
||
198 | |||
199 | }*symbols; |
||
200 | |||
201 | |||
202 | |||
203 | static struct SEGMENT{ |
||
204 | |||
205 | unsigned short idx; |
||
206 | |||
207 | unsigned short segm; |
||
208 | |||
209 | unsigned short ofs; |
||
210 | |||
211 | unsigned short size; |
||
212 | |||
213 | unsigned short scopei; |
||
214 | |||
215 | unsigned short scopec; |
||
216 | |||
217 | unsigned short correli; |
||
218 | |||
219 | unsigned short correlc; |
||
220 | |||
221 | }*segment; |
||
222 | |||
223 | |||
224 | |||
225 | unsigned char dbg=FALSE,dbgact; |
||
226 | |||
227 | static short numsymbols=0; |
||
228 | |||
229 | static int sizetabsym=MAXNUMSYM; |
||
230 | |||
231 | static unsigned short numcorrel; |
||
232 | |||
233 | static unsigned char *bufname; |
||
234 | |||
235 | static int lastofspul=0; |
||
236 | |||
237 | static int segcode; |
||
238 | |||
239 | |||
240 | |||
241 | static struct _COR_INFO_ |
||
242 | |||
243 | { |
||
244 | |||
245 | unsigned int ofs; //начало блока |
||
246 | |||
247 | unsigned int end; //конец блока |
||
248 | |||
249 | unsigned int startline; //номер первой строки информации |
||
250 | |||
251 | unsigned short count; //число строк |
||
252 | |||
253 | unsigned short file; //файл |
||
254 | |||
255 | }*corinfo=NULL; |
||
256 | |||
257 | |||
258 | |||
259 | void InitDbg() |
||
260 | |||
261 | { |
||
262 | |||
263 | if(fobj)dbg&=0xFE; |
||
264 | |||
265 | if(dbg&&(dbgloc==NULL)){ |
||
266 | |||
267 | dbgloc=(unsigned int *)MALLOC(MAXDBGS*sizeof(unsigned int)); |
||
268 | |||
269 | dbgnum=(unsigned int *)MALLOC(MAXDBGS*sizeof(unsigned int)); |
||
270 | |||
271 | dbgmod=(unsigned short *)MALLOC(MAXDBGS*sizeof(unsigned short)); |
||
272 | |||
273 | dbgact=1; //запретить сбор информации |
||
274 | |||
275 | } |
||
276 | |||
277 | if((dbg&2)&&lstflag==NULL){ |
||
278 | |||
279 | lststring=(char **)MALLOC(MAXDBGS*sizeof(char *)); |
||
280 | |||
281 | lstflag=(unsigned char *)MALLOC(MAXDBGS*sizeof(char)); |
||
282 | |||
283 | lstend=(unsigned int *)MALLOC(MAXDBGS*sizeof(unsigned int)); |
||
284 | |||
285 | memset((char *)lstflag,-1,MAXDBGS*sizeof(char)); |
||
286 | |||
287 | memset((unsigned int *)lstend,0,MAXDBGS*sizeof(unsigned int)); |
||
288 | |||
289 | } |
||
290 | |||
291 | } |
||
292 | |||
293 | |||
294 | |||
295 | void AddDataLine(char ssize/*,char typev*/) |
||
296 | |||
297 | { |
||
298 | |||
299 | /* if(typev==pointer||typev==farpointer)ssize=(typev==pointer?(char)2:(char)4); |
||
300 | |||
301 | else*/ //if(tok==tk_string)ssize=(char)3; |
||
302 | |||
303 | lsttypedata=(unsigned char)(ssize<<1); |
||
304 | |||
305 | AddLine(); |
||
306 | |||
307 | lsttypedata=0; |
||
308 | |||
309 | } |
||
310 | |||
311 | |||
312 | |||
313 | void AddDataNullLine(char ssize,char *name) |
||
314 | |||
315 | { |
||
316 | |||
317 | oline--; |
||
318 | |||
319 | |||
320 | |||
321 | lsttypedata=(unsigned char)(ssize<<1); |
||
322 | |||
323 | AddLine(TRUE); |
||
324 | |||
325 | lsttypedata=0; |
||
326 | |||
327 | dbgnum[pdbg-1]=0; //очистить номер строки |
||
328 | |||
329 | //new !!! |
||
330 | |||
331 | if(name!=NULL)lststring[pdbg-1]=BackString(name); |
||
332 | |||
333 | } |
||
334 | |||
335 | |||
336 | |||
337 | void AddCodeNullLine(char *name) |
||
338 | |||
339 | { |
||
340 | |||
341 | oline--; |
||
342 | |||
343 | AddLine(TRUE); |
||
344 | |||
345 | dbgnum[pdbg-1]=0; //очистить номер строки |
||
346 | |||
347 | if(name!=NULL)lststring[pdbg-1]=BackString(name); |
||
348 | |||
349 | oline--; |
||
350 | |||
351 | } |
||
352 | |||
353 | |||
354 | |||
355 | void AddEndLine() |
||
356 | |||
357 | { |
||
358 | |||
359 | if(pdbg/*&&lstend[pdbg-1]==0*/)lstend[pdbg-1]=outptr; |
||
360 | |||
361 | } |
||
362 | |||
363 | |||
364 | |||
365 | void AddLine(int SkipLineInfo) |
||
366 | |||
367 | { |
||
368 | |||
369 | if(/*ooutptr!=outptr&&*/dbgact==0&&(oline!=linenumber||omodule!=currentfileinfo)){ |
||
370 | |||
371 | while(ooutptr>outptr&&pdbg!=0&&ooutptr!=0xffffffff)KillLastLine(); |
||
372 | |||
373 | if(pdbg==pdbgmax){ |
||
374 | |||
375 | pdbgmax+=MAXDBGS; |
||
376 | |||
377 | dbgloc=(unsigned int *) REALLOC(dbgloc,pdbgmax*sizeof(unsigned int)); |
||
378 | |||
379 | dbgnum=(unsigned int *) REALLOC(dbgnum,pdbgmax*sizeof(unsigned int)); |
||
380 | |||
381 | dbgmod=(unsigned short *)REALLOC(dbgmod,pdbgmax*sizeof(unsigned short)); |
||
382 | |||
383 | if(lstflag){ |
||
384 | |||
385 | lststring=(char **)REALLOC(lststring,pdbgmax*sizeof(char *)); |
||
386 | |||
387 | lstflag=(unsigned char *)REALLOC(lstflag,pdbgmax*sizeof(char)); |
||
388 | |||
389 | lstend=(unsigned int *)REALLOC(lstend,pdbgmax*sizeof(unsigned int)); |
||
390 | |||
391 | memset((char *)lstflag+(pdbgmax-MAXDBGS),-1,MAXDBGS*sizeof(char)); |
||
392 | |||
393 | memset((unsigned int *)lstend+(pdbgmax-MAXDBGS),0,MAXDBGS*sizeof(unsigned int)); |
||
394 | |||
395 | } |
||
396 | |||
397 | } |
||
398 | |||
399 | dbgloc[pdbg]=ooutptr=outptr; |
||
400 | |||
401 | dbgnum[pdbg]=oline=linenumber; |
||
402 | |||
403 | dbgmod[pdbg]=(unsigned short)currentfileinfo; |
||
404 | |||
405 | omodule=currentfileinfo; |
||
406 | |||
407 | if(dbg&2){ |
||
408 | |||
409 | if(SkipLineInfo)lststring[pdbg]=NULL; |
||
410 | |||
411 | else{ |
||
412 | |||
413 | char *ofs=startline; |
||
414 | |||
415 | char c; |
||
416 | |||
417 | int sizestring=0; |
||
418 | |||
419 | char buf[MAXLSTSTR]; |
||
420 | |||
421 | for(;sizestring<(MAXLSTSTR-1);sizestring++){ |
||
422 | |||
423 | c=*ofs; |
||
424 | |||
425 | ofs=ofs+1; |
||
426 | |||
427 | if(c==13||ofs==endinput)break; |
||
428 | |||
429 | buf[sizestring]=c; |
||
430 | |||
431 | } |
||
432 | |||
433 | buf[sizestring]=0; |
||
434 | |||
435 | strbtrim(buf); |
||
436 | |||
437 | if((sizestring=strlen(buf))==0)lststring[pdbg]=NULL; |
||
438 | |||
439 | else{ |
||
440 | |||
441 | lststring[pdbg]=(char *)MALLOC(sizestring+1); |
||
442 | |||
443 | strcpy(lststring[pdbg],buf); |
||
444 | |||
445 | } |
||
446 | |||
447 | } |
||
448 | |||
449 | lstflag[pdbg]=(unsigned char)(am32|lsttypedata); |
||
450 | |||
451 | AddEndLine(); |
||
452 | |||
453 | // printf("%s(%d) outptr=%d\n",(startfileinfo+currentfileinfo)->filename,linenumber,outptr); |
||
454 | |||
455 | } |
||
456 | |||
457 | pdbg++; |
||
458 | |||
459 | (startfileinfo+currentfileinfo)->numdline++; |
||
460 | |||
461 | } |
||
462 | |||
463 | } |
||
464 | |||
465 | |||
466 | |||
467 | void KillLastLine() |
||
468 | |||
469 | { |
||
470 | |||
471 | // printf("dbgact=%d pdbg=%d outptr=%08X ooutptr=%08X\n",dbgact,pdbg,outptr,ooutptr); |
||
472 | |||
473 | if(outptr==0&&ooutptr==0x100){ |
||
474 | |||
475 | ooutptr=0; |
||
476 | |||
477 | return; |
||
478 | |||
479 | } |
||
480 | |||
481 | if(dbgact==0&&pdbg!=0){ |
||
482 | |||
483 | // printf("pdbg=%d dbgmod=%d currentfileinfo=%d\n",pdbg,dbgmod[0],currentfileinfo); |
||
484 | |||
485 | if(pdbg==1&&dbgmod[0]!=(unsigned short)currentfileinfo)return; |
||
486 | |||
487 | pdbg--; |
||
488 | |||
489 | if(pdbg==0){ |
||
490 | |||
491 | oline=0; |
||
492 | |||
493 | omodule=ooutptr=0xFFFFFFFF; |
||
494 | |||
495 | } |
||
496 | |||
497 | else{ |
||
498 | |||
499 | oline=dbgnum[pdbg]; |
||
500 | |||
501 | omodule=dbgmod[pdbg]; |
||
502 | |||
503 | ooutptr=dbgloc[pdbg]; |
||
504 | |||
505 | } |
||
506 | |||
507 | // printf("%s(%d) pdbg=%d oline=%d ooutptr=%d\n",(startfileinfo+currentfileinfo)->filename,linenumber,pdbg,oline,ooutptr); |
||
508 | |||
509 | (startfileinfo+dbgmod[pdbg])->numdline--; |
||
510 | |||
511 | } |
||
512 | |||
513 | } |
||
514 | |||
515 | |||
516 | |||
517 | //создание отладочного файла |
||
518 | |||
519 | void DoTDS() |
||
520 | |||
521 | { |
||
522 | |||
523 | int retcode; |
||
524 | |||
525 | unsigned int i,j; |
||
526 | |||
527 | //создать файл |
||
528 | |||
529 | if(lstflag)GeneratLst(); |
||
530 | |||
531 | if(dbg&1){ |
||
532 | |||
533 | //убрать из списка файлов не используемые |
||
534 | |||
535 | for(i=0;i |
||
536 | |||
537 | if((startfileinfo+i)->numdline==0){ |
||
538 | |||
539 | totalmodule--; |
||
540 | |||
541 | if(totalmodule!=i){ |
||
542 | |||
543 | memcpy(&(startfileinfo+i)->filename, |
||
544 | |||
545 | &(startfileinfo+totalmodule)->filename,sizeof(FILEINFO)); |
||
546 | |||
547 | //корректировка таблиц строк |
||
548 | |||
549 | for(j=0;j |
||
550 | |||
551 | if(dbgmod[j]==(unsigned short)totalmodule)dbgmod[j]=(unsigned short)i; |
||
552 | |||
553 | } |
||
554 | |||
555 | i--; |
||
556 | |||
557 | } |
||
558 | |||
559 | } |
||
560 | |||
561 | } |
||
562 | |||
563 | //создать таблицу корреляций |
||
564 | |||
565 | corinfo=(struct _COR_INFO_ *)MALLOC(sizeof(_COR_INFO_)); |
||
566 | |||
567 | corinfo->ofs=dbgloc[0]; |
||
568 | |||
569 | corinfo->startline=0; |
||
570 | |||
571 | omodule=corinfo->file=dbgmod[0]; |
||
572 | |||
573 | numcorrel=0; |
||
574 | |||
575 | for(j=1;j |
||
576 | |||
577 | if((unsigned short)omodule!=dbgmod[j]){ |
||
578 | |||
579 | (corinfo+numcorrel)->count=(unsigned short)(j-(corinfo+numcorrel)->startline); |
||
580 | |||
581 | (corinfo+numcorrel)->end=dbgloc[j]-1; |
||
582 | |||
583 | numcorrel++; |
||
584 | |||
585 | corinfo=(struct _COR_INFO_ *)REALLOC(corinfo,sizeof(_COR_INFO_)*(numcorrel+1)); |
||
586 | |||
587 | (corinfo+numcorrel)->ofs=dbgloc[j]; |
||
588 | |||
589 | (corinfo+numcorrel)->startline=j; |
||
590 | |||
591 | omodule=(corinfo+numcorrel)->file=dbgmod[j]; |
||
592 | |||
593 | } |
||
594 | |||
595 | } |
||
596 | |||
597 | (corinfo+numcorrel)->count=(unsigned short)(pdbg-(corinfo+numcorrel)->startline); |
||
598 | |||
599 | (corinfo+numcorrel)->end=dbgloc[j-1]+1; |
||
600 | |||
601 | numcorrel++; |
||
602 | |||
603 | hout=CreateOutPut("tds","wb"); |
||
604 | |||
605 | if(am32)retcode=CreateW32Debug(); |
||
606 | |||
607 | else retcode=CreateDosDebug(); |
||
608 | |||
609 | if(retcode==0&&fwrite(output,outptr,1,hout)!=1)retcode=-1; |
||
610 | |||
611 | if(retcode!=0)ErrWrite(); |
||
612 | |||
613 | fclose(hout); |
||
614 | |||
615 | hout=NULL; |
||
616 | |||
617 | } |
||
618 | |||
619 | } |
||
620 | |||
621 | |||
622 | |||
623 | void AddNameToTable(char *name) |
||
624 | |||
625 | { |
||
626 | |||
627 | int i=0; |
||
628 | |||
629 | char c; |
||
630 | |||
631 | do{ |
||
632 | |||
633 | c=name[i++]; |
||
634 | |||
635 | op(c); |
||
636 | |||
637 | }while(c!=0); |
||
638 | |||
639 | } |
||
640 | |||
641 | |||
642 | |||
643 | void AddSymbolList(struct idrec *ptr) |
||
644 | |||
645 | { |
||
646 | |||
647 | if(ptr!=NULL){ |
||
648 | |||
649 | AddSymbolList(ptr->right); |
||
650 | |||
651 | if((ptr->rectok==tk_proc&&ptr->recsegm>=NOT_DYNAMIC)|| |
||
652 | |||
653 | (ptr->rectok==tk_interruptproc&&ptr->recsegm>=NOT_DYNAMIC)|| |
||
654 | |||
655 | (ptr->rectok>=tk_bits&&ptr->rectok<=tk_doublevar&&modelmem!=SMALL)|| |
||
656 | |||
657 | (ptr->rectok==tk_structvar&&modelmem!=SMALL)){ |
||
658 | |||
659 | AddNameToTable(ptr->recid); |
||
660 | |||
661 | (symbols+numsymbols)->idxname=numsymbols+1; |
||
662 | |||
663 | (symbols+numsymbols)->ofs=(unsigned short)(ptr->recpost==0? |
||
664 | |||
665 | (unsigned short)ptr->recnumber: |
||
666 | |||
667 | (unsigned short)ptr->recnumber+ooutptr); |
||
668 | |||
669 | if(modelmem==TINY&&comfile==file_exe)(symbols+numsymbols)->ofs-=(unsigned short)0x100; |
||
670 | |||
671 | // if(ptr->rectok==tk_proc)(symbols+numsymbols)->clas=0x18; |
||
672 | |||
673 | numsymbols++; |
||
674 | |||
675 | if(numsymbols==sizetabsym){ |
||
676 | |||
677 | symbols=(_SMB_ *)REALLOC(symbols,(sizetabsym+MAXNUMSYM)*sizeof(_SMB_)); |
||
678 | |||
679 | memset(&(symbols+sizetabsym)->idxname,0,sizeof(_SMB_)*MAXNUMSYM); |
||
680 | |||
681 | sizetabsym+=MAXNUMSYM; |
||
682 | |||
683 | } |
||
684 | |||
685 | } |
||
686 | |||
687 | AddSymbolList(ptr->left); |
||
688 | |||
689 | } |
||
690 | |||
691 | } |
||
692 | |||
693 | |||
694 | |||
695 | void AddNameToPul(char *name) |
||
696 | |||
697 | { |
||
698 | |||
699 | static int sizebuf=0; |
||
700 | |||
701 | int i; |
||
702 | |||
703 | i=strlen(name); |
||
704 | |||
705 | if((lastofspul+i+2)>=sizebuf){ |
||
706 | |||
707 | sizebuf+=STRLEN; |
||
708 | |||
709 | if(sizebuf==STRLEN)bufname=(unsigned char *)MALLOC(sizebuf); |
||
710 | |||
711 | else bufname=(unsigned char *)REALLOC(bufname,sizebuf); |
||
712 | |||
713 | } |
||
714 | |||
715 | bufname[lastofspul++]=(unsigned char)i; |
||
716 | |||
717 | strcpy((char *)(bufname+lastofspul),name); |
||
718 | |||
719 | lastofspul+=++i; |
||
720 | |||
721 | } |
||
722 | |||
723 | |||
724 | |||
725 | void AddGlobalName(struct idrec *ptr) |
||
726 | |||
727 | { |
||
728 | |||
729 | if(ptr!=NULL){ |
||
730 | |||
731 | AddGlobalName(ptr->right); |
||
732 | |||
733 | if((ptr->rectok==tk_proc&&ptr->recsegm>=NOT_DYNAMIC)|| |
||
734 | |||
735 | (ptr->rectok>=tk_bits&&ptr->rectok<=tk_doublevar)|| |
||
736 | |||
737 | (ptr->rectok==tk_structvar)){ |
||
738 | |||
739 | AddNameToPul(ptr->recid); |
||
740 | |||
741 | numsymbols++; |
||
742 | |||
743 | if(ptr->rectok==tk_proc){ |
||
744 | |||
745 | outword(0x1c); //size |
||
746 | |||
747 | outdword(0x20); //type |
||
748 | |||
749 | } |
||
750 | |||
751 | else{ |
||
752 | |||
753 | outword(0x18); |
||
754 | |||
755 | outdword(0x21); |
||
756 | |||
757 | } |
||
758 | |||
759 | outword(0); |
||
760 | |||
761 | outdword(0); |
||
762 | |||
763 | outdword(numsymbols); //name |
||
764 | |||
765 | outdword(0); |
||
766 | |||
767 | if(ptr->recpost==0){ |
||
768 | |||
769 | outdword(ptr->recnumber); //offset |
||
770 | |||
771 | outword(segcode); //segm |
||
772 | |||
773 | } |
||
774 | |||
775 | else{ |
||
776 | |||
777 | outdword(ptr->recnumber+(wbss!=FALSE?0:ooutptr)); |
||
778 | |||
779 | outword(1); |
||
780 | |||
781 | } |
||
782 | |||
783 | if(ptr->rectok==tk_proc)outdword(0); |
||
784 | |||
785 | } |
||
786 | |||
787 | AddGlobalName(ptr->left); |
||
788 | |||
789 | } |
||
790 | |||
791 | } |
||
792 | |||
793 | |||
794 | |||
795 | int CreateW32Debug() |
||
796 | |||
797 | { |
||
798 | |||
799 | int sstNames,sstDirectory; |
||
800 | |||
801 | int startcode=outptr; |
||
802 | |||
803 | int sstGlobalSym; |
||
804 | |||
805 | int sstsrc; |
||
806 | |||
807 | unsigned int i,j,jj,ofs; |
||
808 | |||
809 | for(;numsymbols<(short)totalmodule;numsymbols++)AddNameToPul((startfileinfo+numsymbols)->filename); |
||
810 | |||
811 | segcode=(wbss==FALSE?1:2); |
||
812 | |||
813 | outptr=0; |
||
814 | |||
815 | outdword(0x41304246); // TDS - signature |
||
816 | |||
817 | outdword(0); // offset of Subsection Directory (fill later) |
||
818 | |||
819 | //sstModule subsection |
||
820 | |||
821 | outdword(0); // OvlNum=0 & LibIndex=0 |
||
822 | |||
823 | outword(segcode); // SegCount |
||
824 | |||
825 | outword(0x5643); // CV-style |
||
826 | |||
827 | outdword(1); // Name |
||
828 | |||
829 | for(i=0;i<4;i++)outdword(0); |
||
830 | |||
831 | // outdword(0); //Time |
||
832 | |||
833 | // outdword(0); |
||
834 | |||
835 | // outdword(0); |
||
836 | |||
837 | // outdword(0); |
||
838 | |||
839 | if(wbss){ |
||
840 | |||
841 | outword(0x0001); // SegNumber |
||
842 | |||
843 | outword(0); // flag |
||
844 | |||
845 | outdword(0); // start |
||
846 | |||
847 | outdword(postsize); // len |
||
848 | |||
849 | } |
||
850 | |||
851 | outword(segcode); // SegNumber |
||
852 | |||
853 | outword(0x0001); // flag |
||
854 | |||
855 | outdword(startptr); // start |
||
856 | |||
857 | outdword(startcode); // len |
||
858 | |||
859 | sstsrc=outptr; |
||
860 | |||
861 | //sstSrcModule subsection |
||
862 | |||
863 | outword((short)numcorrel); //cFile - количество SRC-файлов(сегментов) |
||
864 | |||
865 | outword((short)numcorrel); // SegCount (see SegCount in sstModule |
||
866 | |||
867 | ofs=14*numcorrel+4; |
||
868 | |||
869 | for(i=0,jj=0;i<(unsigned int)numcorrel;i++){ |
||
870 | |||
871 | if(i!=0)jj=jj+((corinfo+i-1)->count+1)*6+22; |
||
872 | |||
873 | outdword(ofs+jj); |
||
874 | |||
875 | } |
||
876 | |||
877 | for(i=0;i<(unsigned int)numcorrel;i++){ |
||
878 | |||
879 | outdword((corinfo+i)->ofs); |
||
880 | |||
881 | outdword((corinfo+i)->end); |
||
882 | |||
883 | } |
||
884 | |||
885 | for(i=0;i<(unsigned int)numcorrel;i++)outword(segcode); // массив индексов сегментов |
||
886 | |||
887 | for(i=0;i<(unsigned int)numcorrel;i++){ |
||
888 | |||
889 | outword(1); // Segm# |
||
890 | |||
891 | outdword((corinfo+i)->file+1);// File# |
||
892 | |||
893 | outdword(outptr-sstsrc+12); |
||
894 | |||
895 | outdword((corinfo+i)->ofs); |
||
896 | |||
897 | outdword((corinfo+i)->end); |
||
898 | |||
899 | outword(segcode); //Segm# |
||
900 | |||
901 | jj=(corinfo+i)->count; |
||
902 | |||
903 | outword(jj+1); // Lines count |
||
904 | |||
905 | ofs=(corinfo+i)->startline; |
||
906 | |||
907 | for(j=0;j |
||
908 | |||
909 | outdword((corinfo+i)->end); |
||
910 | |||
911 | for(j=0;j |
||
912 | |||
913 | outword(0); |
||
914 | |||
915 | } |
||
916 | |||
917 | //таблица глобальных символов |
||
918 | |||
919 | sstGlobalSym=outptr; |
||
920 | |||
921 | for(i=0;i<8;i++)outdword(0); |
||
922 | |||
923 | // outdword(0); //modindex |
||
924 | |||
925 | // outdword(0); //size correct later |
||
926 | |||
927 | // outdword(0); |
||
928 | |||
929 | // outdword(0); |
||
930 | |||
931 | // outdword(0); |
||
932 | |||
933 | // outdword(0); //num others correct later |
||
934 | |||
935 | // outdword(0); //total correct later |
||
936 | |||
937 | // outdword(0); //SymHash, AddrHash |
||
938 | |||
939 | outdword(0x02100008); //S_ENTRY32 |
||
940 | |||
941 | outdword(EntryPoint()); |
||
942 | |||
943 | outword(segcode); |
||
944 | |||
945 | AddGlobalName(treestart); |
||
946 | |||
947 | sstNames=outptr; |
||
948 | |||
949 | outdword(numsymbols); |
||
950 | |||
951 | outptr=sstGlobalSym+4; |
||
952 | |||
953 | outdword(sstNames-sstGlobalSym-32); |
||
954 | |||
955 | outptr+=12; |
||
956 | |||
957 | outdword(numsymbols-totalmodule); |
||
958 | |||
959 | outdword(numsymbols-totalmodule); |
||
960 | |||
961 | outptr=4; |
||
962 | |||
963 | sstDirectory=sstNames+4+lastofspul; |
||
964 | |||
965 | outdword(sstDirectory); |
||
966 | |||
967 | if(fwrite(output,sstNames+4,1,hout)!=1)return -1; |
||
968 | |||
969 | if(fwrite(bufname,lastofspul,1,hout)!=1)return -1; |
||
970 | |||
971 | free(bufname); |
||
972 | |||
973 | // Subsection Directory |
||
974 | |||
975 | outptr=0; |
||
976 | |||
977 | outdword(0x0C0010); |
||
978 | |||
979 | outdword(4); // cDir - number of subsections |
||
980 | |||
981 | outdword(0); |
||
982 | |||
983 | outdword(0); |
||
984 | |||
985 | //sstModule |
||
986 | |||
987 | outdword(0x10120); |
||
988 | |||
989 | outdword(8); //start |
||
990 | |||
991 | outdword(sstsrc-8); // size |
||
992 | |||
993 | // sstSrcModule |
||
994 | |||
995 | outdword(0x10127); |
||
996 | |||
997 | outdword(sstsrc); //start |
||
998 | |||
999 | outdword(sstNames-sstsrc);//size |
||
1000 | |||
1001 | //sstGlobalSym |
||
1002 | |||
1003 | outdword(0x129); |
||
1004 | |||
1005 | outdword(sstGlobalSym); //start |
||
1006 | |||
1007 | outdword(sstNames-sstGlobalSym); //size |
||
1008 | |||
1009 | // sstNames |
||
1010 | |||
1011 | outdword(0x130); |
||
1012 | |||
1013 | outdword(sstNames); |
||
1014 | |||
1015 | outdword(sstDirectory-sstGlobalSym); |
||
1016 | |||
1017 | outdword(0x41304246); // TDS - signature |
||
1018 | |||
1019 | outdword(sstDirectory+outptr+4); // TDS-len |
||
1020 | |||
1021 | return 0; |
||
1022 | |||
1023 | } |
||
1024 | |||
1025 | |||
1026 | |||
1027 | int CreateDosDebug() |
||
1028 | |||
1029 | { |
||
1030 | |||
1031 | unsigned int i,j,count; |
||
1032 | |||
1033 | D16START d16header; |
||
1034 | |||
1035 | MODULE *module; |
||
1036 | |||
1037 | SFT *sft; |
||
1038 | |||
1039 | LT *lt; |
||
1040 | |||
1041 | CT *ct; |
||
1042 | |||
1043 | int corrnum=0,ii; |
||
1044 | |||
1045 | unsigned short beg,end; |
||
1046 | |||
1047 | outptr=0; |
||
1048 | |||
1049 | //16-бит заголовок |
||
1050 | |||
1051 | memset(&d16header,0,sizeof(D16START)); |
||
1052 | |||
1053 | //таблица глобальных имен |
||
1054 | |||
1055 | symbols=(_SMB_ *)MALLOC(sizeof(_SMB_)*MAXNUMSYM); |
||
1056 | |||
1057 | memset(symbols,0,sizeof(_SMB_)*MAXNUMSYM); |
||
1058 | |||
1059 | AddSymbolList(treestart); |
||
1060 | |||
1061 | d16header.numname=totalmodule*2+numsymbols; |
||
1062 | |||
1063 | d16header.numsymbl=d16header.numgsymb=numsymbols; |
||
1064 | |||
1065 | |||
1066 | |||
1067 | d16header.sign=0x040352FB; //sign & version |
||
1068 | |||
1069 | d16header.imagesize=runfilesize; //image size |
||
1070 | |||
1071 | d16header.numsours=totalmodule; //1 |
||
1072 | |||
1073 | d16header.numline=pdbg; //lines |
||
1074 | |||
1075 | d16header.numincl=totalmodule; //include files |
||
1076 | |||
1077 | d16header.numseg=totalmodule;//totalmodule; //1 |
||
1078 | |||
1079 | d16header.numcorrel=numcorrel;//totalmodule; //Correlation |
||
1080 | |||
1081 | d16header.casesensiv=1; |
||
1082 | |||
1083 | // d16header.numtentr=NUMTYPES; |
||
1084 | |||
1085 | //только для 128-байтового заголовка |
||
1086 | |||
1087 | // d16header.fdebug=1; |
||
1088 | |||
1089 | |||
1090 | |||
1091 | d16header.ucnovn=0x380000; |
||
1092 | |||
1093 | d16header.sizeblock=sizeof(MODULE)*totalmodule+sizeof(SFT)*totalmodule+ |
||
1094 | |||
1095 | sizeof(LT)*pdbg+sizeof(SEGMENT)*totalmodule+sizeof(CT)*numcorrel+ |
||
1096 | |||
1097 | 6*totalmodule+/*NUMTYPES*12+*/sizeof(_SMB_)*numsymbols/*+numsymbols*4*/; |
||
1098 | |||
1099 | d16header.reftsize=numsymbols*4; |
||
1100 | |||
1101 | |||
1102 | |||
1103 | //module table |
||
1104 | |||
1105 | module=(struct MODULE *)MALLOC(sizeof(MODULE)*totalmodule); |
||
1106 | |||
1107 | memset(module,0,sizeof(MODULE)*totalmodule); |
||
1108 | |||
1109 | //sourse file table |
||
1110 | |||
1111 | sft=(SFT *)MALLOC(sizeof(SFT)*totalmodule); |
||
1112 | |||
1113 | //segment table |
||
1114 | |||
1115 | segment=(struct SEGMENT *)MALLOC(sizeof(SEGMENT)*totalmodule); |
||
1116 | |||
1117 | memset(segment,0,sizeof(SEGMENT)*totalmodule); |
||
1118 | |||
1119 | //correlation table |
||
1120 | |||
1121 | ct=(CT *)MALLOC(sizeof(CT)*numcorrel); |
||
1122 | |||
1123 | for(i=0;i |
||
1124 | |||
1125 | //имена модулей |
||
1126 | |||
1127 | AddNameToTable((startfileinfo+i)->filename); |
||
1128 | |||
1129 | strcpy((char *)string3,(startfileinfo+i)->filename); |
||
1130 | |||
1131 | char *str=strrchr((char *)string3,'.'); |
||
1132 | |||
1133 | if(str!=0){ |
||
1134 | |||
1135 | str[0]=0; |
||
1136 | |||
1137 | str=strrchr((char *)string3,'\\'); |
||
1138 | |||
1139 | if(str==NULL)str=(char *)string3; |
||
1140 | |||
1141 | else str++; |
||
1142 | |||
1143 | } |
||
1144 | |||
1145 | else str=(char *)string3; |
||
1146 | |||
1147 | AddNameToTable(str); |
||
1148 | |||
1149 | //таблица модулей |
||
1150 | |||
1151 | (module+i)->name=i*2+2+numsymbols; |
||
1152 | |||
1153 | (module+i)->language=1; |
||
1154 | |||
1155 | (module+i)->memmodel=8;//modelmem==SMALL&&comfile==file_exe?9:8; |
||
1156 | |||
1157 | (module+i)->sourcount=1;//(unsigned short)totalmodule; |
||
1158 | |||
1159 | (module+i)->sourindex=(unsigned short)(i+1); |
||
1160 | |||
1161 | //информация об исходных файлах |
||
1162 | |||
1163 | (sft+i)->idx=i*2+1+numsymbols; |
||
1164 | |||
1165 | (sft+i)->time=(startfileinfo+i)->time; |
||
1166 | |||
1167 | count=0; //число кореляций для данного модуля |
||
1168 | |||
1169 | for(ii=0;ii |
||
1170 | |||
1171 | if((corinfo+ii)->file==(unsigned short)i){ //корр для этого модуля |
||
1172 | |||
1173 | if(count==0){ //первый блок |
||
1174 | |||
1175 | (segment+i)->ofs=beg=(unsigned short)(corinfo+ii)->ofs; |
||
1176 | |||
1177 | (segment+i)->correli=(unsigned short)(corrnum+1); //correlation index |
||
1178 | |||
1179 | (module+i)->corindex=(unsigned short)(corrnum+1); |
||
1180 | |||
1181 | } |
||
1182 | |||
1183 | (ct+corrnum)->beg=(corinfo+ii)->startline+1; |
||
1184 | |||
1185 | (ct+corrnum)->segidx=(unsigned short)(1+i); //segment idx |
||
1186 | |||
1187 | (ct+corrnum)->filidx=(unsigned short)(i+1); //file idx |
||
1188 | |||
1189 | (ct+corrnum)->count=(corinfo+ii)->count; //число линий |
||
1190 | |||
1191 | end=(unsigned short)(corinfo+ii)->end; |
||
1192 | |||
1193 | corrnum++; |
||
1194 | |||
1195 | count++; |
||
1196 | |||
1197 | } |
||
1198 | |||
1199 | } |
||
1200 | |||
1201 | //таблица сегментов |
||
1202 | |||
1203 | (segment+i)->idx=(unsigned short)(i+1); //segment index |
||
1204 | |||
1205 | (segment+i)->size=(unsigned short)(end-beg);//length |
||
1206 | |||
1207 | (segment+i)->correlc=(unsigned short)count;//(unsigned short)totalmodule; //correlation count |
||
1208 | |||
1209 | (module+i)->corcount=(unsigned short)count; |
||
1210 | |||
1211 | if(modelmem==TINY&&comfile==file_exe)(segment+i)->segm=0xfff0; |
||
1212 | |||
1213 | } |
||
1214 | |||
1215 | d16header.pol_size=outptr; |
||
1216 | |||
1217 | if(fwrite(&d16header,sizeof(D16START),1,hout)!=1)return -1; |
||
1218 | |||
1219 | if(fwrite(symbols,sizeof(_SMB_)*numsymbols,1,hout)!=1)return -1; |
||
1220 | |||
1221 | if(fwrite(module,sizeof(MODULE)*totalmodule,1,hout)!=1)return -1; |
||
1222 | |||
1223 | free(module); |
||
1224 | |||
1225 | if(fwrite(sft,sizeof(SFT)*totalmodule,1,hout)!=1)return -1; |
||
1226 | |||
1227 | free(sft); |
||
1228 | |||
1229 | //line table |
||
1230 | |||
1231 | lt=(LT *)MALLOC(sizeof(LT)*pdbg); |
||
1232 | |||
1233 | for(j=0;(unsigned int)j |
||
1234 | |||
1235 | // printf("line %d loc %X\n",dbgnum[j],dbgloc[j]); |
||
1236 | |||
1237 | (lt+j)->line=(unsigned short)dbgnum[j]; |
||
1238 | |||
1239 | (lt+j)->ofs=(unsigned short)dbgloc[j]; |
||
1240 | |||
1241 | } |
||
1242 | |||
1243 | if(fwrite(lt,sizeof(LT)*pdbg,1,hout)!=1)return -1; |
||
1244 | |||
1245 | free(lt); |
||
1246 | |||
1247 | if(fwrite(segment,sizeof(SEGMENT)*totalmodule,1,hout)!=1)return -1; |
||
1248 | |||
1249 | free(segment); |
||
1250 | |||
1251 | if(fwrite(ct,sizeof(CT)*numcorrel,1,hout)!=1)return -1; |
||
1252 | |||
1253 | free(ct); |
||
1254 | |||
1255 | // if(fwrite(types,NUMTYPES*12,1,hout)!=1)return -1; |
||
1256 | |||
1257 | memset(&string3,0,6*totalmodule); |
||
1258 | |||
1259 | if(fwrite(&string3,6*totalmodule,1,hout)!=1)return -1; |
||
1260 | |||
1261 | /* if(numsymbols){ |
||
1262 | |||
1263 | memset(symbols,0,4*numsymbols); |
||
1264 | |||
1265 | if(fwrite(symbols,4*numsymbols,1,hout)!=1)return -1; |
||
1266 | |||
1267 | }*/ |
||
1268 | |||
1269 | free(symbols); |
||
1270 | |||
1271 | return 0; |
||
1272 | |||
1273 | } |
||
1274 | |||
1275 | |||
1276 | |||
1277 | void KillDataLine(int line) |
||
1278 | |||
1279 | { |
||
1280 | |||
1281 | (startfileinfo+dbgmod[line])->numdline--; |
||
1282 | |||
1283 | for(unsigned int j=line;(j+1) |
||
1284 | |||
1285 | dbgloc[j]=dbgloc[j+1]; |
||
1286 | |||
1287 | dbgnum[j]=dbgnum[j+1]; |
||
1288 | |||
1289 | dbgmod[j]=dbgmod[j+1]; |
||
1290 | |||
1291 | } |
||
1292 | |||
1293 | lstflag++; |
||
1294 | |||
1295 | lststring++; |
||
1296 | |||
1297 | lstend++; |
||
1298 | |||
1299 | pdbg--; |
||
1300 | |||
1301 | } |
||
1302 | |||
1303 | |||
1304 | |||
1305 | void GeneratLst() |
||
1306 | |||
1307 | { |
||
1308 | |||
1309 | unsigned int j; |
||
1310 | |||
1311 | unsigned long startip; |
||
1312 | |||
1313 | unsigned int offs2,line; |
||
1314 | |||
1315 | unsigned char flag; |
||
1316 | |||
1317 | hout=CreateOutPut("lst","wt"); |
||
1318 | |||
1319 | if(lstend[pdbg-1]==0)lstend[pdbg-1]=endinptr; |
||
1320 | |||
1321 | startip=(comfile!=file_w32&&comfile!=file_bin?0:ImageBase); |
||
1322 | |||
1323 | fprintf(hout,"SPHINX/SHEKER C-- One Pass Disassembler. Version %d.%02d%s %s\n",ver1,ver2,betta,__DATE__); |
||
1324 | |||
1325 | for(j=0;j |
||
1326 | |||
1327 | //printf("line %d loc %X\n",dbgnum[j],dbgloc[j]); |
||
1328 | |||
1329 | if((int)lstflag[j]!=0xFF){ |
||
1330 | |||
1331 | flag=lstflag[j]; |
||
1332 | |||
1333 | offs2=lstend[j]; |
||
1334 | |||
1335 | outptr=dbgloc[j]; |
||
1336 | |||
1337 | instruction_offset=outptr+startip; |
||
1338 | |||
1339 | seg_size=(unsigned char)(16+16*(flag&1)); |
||
1340 | |||
1341 | line=dbgnum[j]; |
||
1342 | |||
1343 | if(offs2!=outptr){ |
||
1344 | |||
1345 | /* |
||
1346 | |||
1347 | if(line!=0)printf("%s %u:",(startfileinfo+dbgmod[j])->filename,line); |
||
1348 | |||
1349 | if(lststring[j]!=NULL)printf(" %s\n",lststring[j]); |
||
1350 | |||
1351 | else if(line!=0)printf("\n"); |
||
1352 | |||
1353 | */ |
||
1354 | |||
1355 | fprintf(hout,"\n"); |
||
1356 | |||
1357 | if(line!=0)fprintf(hout,"%s %u:",(startfileinfo+dbgmod[j])->filename,line); |
||
1358 | |||
1359 | if(lststring[j]!=NULL)fprintf(hout," %s\n",lststring[j]); |
||
1360 | |||
1361 | else if(line!=0)fprintf(hout,"\n"); |
||
1362 | |||
1363 | while(outptr |
||
1364 | |||
1365 | if(flag&0x1e)undata(instruction_offset,offs2-dbgloc[j],(flag>>1)&15); |
||
1366 | |||
1367 | else unassemble(instruction_offset); |
||
1368 | |||
1369 | } |
||
1370 | |||
1371 | } |
||
1372 | |||
1373 | if((dbg&1)!=0&&((flag&0xe)!=0||line==0)){ |
||
1374 | |||
1375 | KillDataLine(j); |
||
1376 | |||
1377 | j--; |
||
1378 | |||
1379 | } |
||
1380 | |||
1381 | } |
||
1382 | |||
1383 | } |
||
1384 | |||
1385 | fclose(hout); |
||
1386 | |||
1387 | hout=NULL; |
||
1388 | |||
1389 | } |
||
1390 | |||
1391 | |||
1392 | |||
1393 | #ifdef DEBUGMODE |
||
1394 | |||
1395 | void printdebuginfo() |
||
1396 | |||
1397 | { |
||
1398 | |||
1399 | static FILE *df=NULL; |
||
1400 | |||
1401 | if((df=fopen("debug.tmp","w+t"))==NULL)df=stdout; |
||
1402 | |||
1403 | fprintf(df,"%s(%d)> %08X %08X tok=%d num=%08X flag=%08X scanmode=%d %s\n",startfileinfo==NULL?"":(startfileinfo+currentfileinfo)->filename,linenumber,input,inptr2,tok,itok.number,itok.flag,scanlexmode,itok.name); |
||
1404 | |||
1405 | fflush(df); |
||
1406 | |||
1407 | } |
||
1408 | |||
1409 | #endif |
||
1410 |