Removed the .xcnlnk section hack, and replaced it by another hack in
[wine.git] / debugger / msc.c
blob152d4895b15b1a2c3eaf8b06af62885229a90e73
1 /*
2 * File msc.c - read VC++ debug information from COFF and eventually
3 * from PDB files.
5 * Copyright (C) 1996, Eric Youngdale.
6 * Copyright (C) 1999, Ulrich Weigand.
8 * Note - this handles reading debug information for 32 bit applications
9 * that run under Windows-NT for example. I doubt that this would work well
10 * for 16 bit applications, but I don't think it really matters since the
11 * file format is different, and we should never get in here in such cases.
13 * TODO:
14 * Get 16 bit CV stuff working.
15 * Add symbol size to internal symbol table.
18 #include "config.h"
19 #include <stdlib.h>
21 #include <string.h>
22 #include <unistd.h>
23 #ifndef PATH_MAX
24 #define PATH_MAX _MAX_PATH
25 #endif
26 #include "debugger.h"
27 #include "neexe.h"
28 #include "pe_image.h"
29 #include "file.h"
31 typedef struct {
32 IMAGE_DEBUG_DIRECTORY dbgdir;
33 u_long sect_ofs;
34 int nsect;
35 char* dbg_info;
36 int dbg_size;
37 } MSC_DBG_INFO;
39 #define MSC_INFO(module) ((MSC_DBG_INFO*)((module)->extra_info))
41 static int DEBUG_ProcessMSCDebugInfo(DBG_MODULE* module);
44 * dbg_filename must be at least MAX_PATHNAME_LEN bytes in size
46 static void DEBUG_LocateDebugInfoFile(const char *filename, char *dbg_filename)
48 char *str1 = DBG_alloc(MAX_PATHNAME_LEN);
49 char *str2 = DBG_alloc(MAX_PATHNAME_LEN*10);
50 const char *file;
51 char *name_part;
53 file = strrchr(filename, '\\');
54 if( file == NULL ) file = filename; else file++;
56 if ((GetEnvironmentVariable("_NT_SYMBOL_PATH", str1, MAX_PATHNAME_LEN) &&
57 (SearchPath(str1, file, NULL, MAX_PATHNAME_LEN*10, str2, &name_part))) ||
58 (GetEnvironmentVariable("_NT_ALT_SYMBOL_PATH", str1, MAX_PATHNAME_LEN) &&
59 (SearchPath(str1, file, NULL, MAX_PATHNAME_LEN*10, str2, &name_part))) ||
60 (SearchPath(NULL, file, NULL, MAX_PATHNAME_LEN*10, str2, &name_part)))
61 lstrcpyn(dbg_filename, str2, MAX_PATHNAME_LEN);
62 else
63 lstrcpyn(dbg_filename, filename, MAX_PATHNAME_LEN);
64 DBG_free(str1);
65 DBG_free(str2);
68 /***********************************************************************
69 * DEBUG_MapDebugInfoFile
71 static void* DEBUG_MapDebugInfoFile(const char* name, DWORD offset, DWORD size,
72 HANDLE* hFile, HANDLE* hMap)
74 OFSTRUCT ofs;
75 DWORD g_offset; /* offset aligned on map granuality */
76 DWORD g_size; /* size to map, with offset aligned */
77 char* ret;
79 *hMap = 0;
81 if (name != NULL) {
82 char filename[MAX_PATHNAME_LEN];
84 DEBUG_LocateDebugInfoFile(name, filename);
85 if ((*hFile = OpenFile(filename, &ofs, OF_READ)) == HFILE_ERROR)
86 return NULL;
89 if (!size) {
90 DWORD file_size = GetFileSize(*hFile, NULL);
91 if (file_size == (DWORD)-1) return NULL;
92 size = file_size - offset;
95 g_offset = offset & ~0xFFFF; /* FIXME: is granularity portable ? */
96 g_size = offset + size - g_offset;
98 if ((*hMap = CreateFileMapping(*hFile, NULL, PAGE_READONLY, 0, 0, NULL)) == 0)
99 return NULL;
101 if ((ret = MapViewOfFile(*hMap, FILE_MAP_READ, 0, g_offset, g_size)) != NULL)
102 ret += offset - g_offset;
103 return ret;
106 /***********************************************************************
107 * DEBUG_UnmapDebugInfoFile
109 static void DEBUG_UnmapDebugInfoFile(HANDLE hFile, HANDLE hMap, void* addr)
111 if (addr) UnmapViewOfFile(addr);
112 if (hMap) CloseHandle(hMap);
113 if (hFile) CloseHandle(hFile);
116 union any_size
118 char * c;
119 short * s;
120 int * i;
121 unsigned int * ui;
125 * This is a convenience structure used to map portions of the
126 * line number table.
128 struct startend
130 unsigned int start;
131 unsigned int end;
135 * This is how we reference the various record types.
137 union codeview_symbol
139 struct
141 short int len;
142 short int id;
143 } generic;
145 struct
147 short int len;
148 short int id;
149 unsigned int offset;
150 unsigned short seg;
151 unsigned short symtype;
152 unsigned char namelen;
153 unsigned char name[1];
154 } data;
156 struct
158 short int len;
159 short int id;
160 unsigned int symtype;
161 unsigned int offset;
162 unsigned short seg;
163 unsigned char namelen;
164 unsigned char name[1];
165 } data32;
167 struct
169 short int len;
170 short int id;
171 unsigned int pparent;
172 unsigned int pend;
173 unsigned int next;
174 unsigned int offset;
175 unsigned short segment;
176 unsigned short thunk_len;
177 unsigned char thtype;
178 unsigned char namelen;
179 unsigned char name[1];
180 } thunk;
182 struct
184 short int len;
185 short int id;
186 unsigned int pparent;
187 unsigned int pend;
188 unsigned int next;
189 unsigned int proc_len;
190 unsigned int debug_start;
191 unsigned int debug_end;
192 unsigned int offset;
193 unsigned short segment;
194 unsigned short proctype;
195 unsigned char flags;
196 unsigned char namelen;
197 unsigned char name[1];
198 } proc;
200 struct
202 short int len;
203 short int id;
204 unsigned int pparent;
205 unsigned int pend;
206 unsigned int next;
207 unsigned int proc_len;
208 unsigned int debug_start;
209 unsigned int debug_end;
210 unsigned int proctype;
211 unsigned int offset;
212 unsigned short segment;
213 unsigned char flags;
214 unsigned char namelen;
215 unsigned char name[1];
216 } proc32;
218 struct
220 short int len; /* Total length of this entry */
221 short int id; /* Always S_BPREL32 */
222 unsigned int offset; /* Stack offset relative to BP */
223 unsigned short symtype;
224 unsigned char namelen;
225 unsigned char name[1];
226 } stack;
228 struct
230 short int len; /* Total length of this entry */
231 short int id; /* Always S_BPREL32 */
232 unsigned int offset; /* Stack offset relative to BP */
233 unsigned int symtype;
234 unsigned char namelen;
235 unsigned char name[1];
236 } stack32;
240 union codeview_type
242 struct
244 short int len;
245 short int id;
246 } generic;
248 struct
250 short int len;
251 short int id;
252 short int attribute;
253 short int datatype;
254 unsigned char variant[1];
255 } pointer;
257 struct
259 short int len;
260 short int id;
261 unsigned int datatype;
262 unsigned int attribute;
263 unsigned char variant[1];
264 } pointer32;
266 struct
268 short int len;
269 short int id;
270 unsigned char nbits;
271 unsigned char bitoff;
272 unsigned short type;
273 } bitfield;
275 struct
277 short int len;
278 short int id;
279 unsigned int type;
280 unsigned char nbits;
281 unsigned char bitoff;
282 } bitfield32;
284 struct
286 short int len;
287 short int id;
288 short int elemtype;
289 short int idxtype;
290 unsigned short int arrlen; /* numeric leaf */
291 #if 0
292 unsigned char name[1];
293 #endif
294 } array;
296 struct
298 short int len;
299 short int id;
300 unsigned int elemtype;
301 unsigned int idxtype;
302 unsigned short int arrlen; /* numeric leaf */
303 #if 0
304 unsigned char name[1];
305 #endif
306 } array32;
308 struct
310 short int len;
311 short int id;
312 short int n_element;
313 short int fieldlist;
314 short int property;
315 short int derived;
316 short int vshape;
317 unsigned short int structlen; /* numeric leaf */
318 #if 0
319 unsigned char name[1];
320 #endif
321 } structure;
323 struct
325 short int len;
326 short int id;
327 short int n_element;
328 short int property;
329 unsigned int fieldlist;
330 unsigned int derived;
331 unsigned int vshape;
332 unsigned short int structlen; /* numeric leaf */
333 #if 0
334 unsigned char name[1];
335 #endif
336 } structure32;
338 struct
340 short int len;
341 short int id;
342 short int count;
343 short int fieldlist;
344 short int property;
345 unsigned short int un_len; /* numeric leaf */
346 #if 0
347 unsigned char name[1];
348 #endif
349 } t_union;
351 struct
353 short int len;
354 short int id;
355 short int count;
356 short int property;
357 unsigned int fieldlist;
358 unsigned short int un_len; /* numeric leaf */
359 #if 0
360 unsigned char name[1];
361 #endif
362 } t_union32;
364 struct
366 short int len;
367 short int id;
368 short int count;
369 short int type;
370 short int field;
371 short int property;
372 unsigned char name[1];
373 } enumeration;
375 struct
377 short int len;
378 short int id;
379 short int count;
380 short int property;
381 unsigned int type;
382 unsigned int field;
383 unsigned char name[1];
384 } enumeration32;
386 struct
388 short int len;
389 short int id;
390 unsigned char list[1];
391 } fieldlist;
394 union codeview_fieldtype
396 struct
398 short int id;
399 } generic;
401 struct
403 short int id;
404 short int type;
405 short int attribute;
406 unsigned short int offset; /* numeric leaf */
407 } bclass;
409 struct
411 short int id;
412 short int attribute;
413 unsigned int type;
414 unsigned short int offset; /* numeric leaf */
415 } bclass32;
417 struct
419 short int id;
420 short int btype;
421 short int vbtype;
422 short int attribute;
423 unsigned short int vbpoff; /* numeric leaf */
424 #if 0
425 unsigned short int vboff; /* numeric leaf */
426 #endif
427 } vbclass;
429 struct
431 short int id;
432 short int attribute;
433 unsigned int btype;
434 unsigned int vbtype;
435 unsigned short int vbpoff; /* numeric leaf */
436 #if 0
437 unsigned short int vboff; /* numeric leaf */
438 #endif
439 } vbclass32;
441 struct
443 short int id;
444 short int attribute;
445 unsigned short int value; /* numeric leaf */
446 #if 0
447 unsigned char name[1];
448 #endif
449 } enumerate;
451 struct
453 short int id;
454 short int type;
455 unsigned char name[1];
456 } friendfcn;
458 struct
460 short int id;
461 short int _pad0;
462 unsigned int type;
463 unsigned char name[1];
464 } friendfcn32;
466 struct
468 short int id;
469 short int type;
470 short int attribute;
471 unsigned short int offset; /* numeric leaf */
472 #if 0
473 unsigned char name[1];
474 #endif
475 } member;
477 struct
479 short int id;
480 short int attribute;
481 unsigned int type;
482 unsigned short int offset; /* numeric leaf */
483 #if 0
484 unsigned char name[1];
485 #endif
486 } member32;
488 struct
490 short int id;
491 short int type;
492 short int attribute;
493 unsigned char name[1];
494 } stmember;
496 struct
498 short int id;
499 short int attribute;
500 unsigned int type;
501 unsigned char name[1];
502 } stmember32;
504 struct
506 short int id;
507 short int count;
508 short int mlist;
509 unsigned char name[1];
510 } method;
512 struct
514 short int id;
515 short int count;
516 unsigned int mlist;
517 unsigned char name[1];
518 } method32;
520 struct
522 short int id;
523 short int index;
524 unsigned char name[1];
525 } nesttype;
527 struct
529 short int id;
530 short int _pad0;
531 unsigned int index;
532 unsigned char name[1];
533 } nesttype32;
535 struct
537 short int id;
538 short int type;
539 } vfunctab;
541 struct
543 short int id;
544 short int _pad0;
545 unsigned int type;
546 } vfunctab32;
548 struct
550 short int id;
551 short int type;
552 } friendcls;
554 struct
556 short int id;
557 short int _pad0;
558 unsigned int type;
559 } friendcls32;
562 struct
564 short int id;
565 short int attribute;
566 short int type;
567 unsigned char name[1];
568 } onemethod;
569 struct
571 short int id;
572 short int attribute;
573 short int type;
574 unsigned int vtab_offset;
575 unsigned char name[1];
576 } onemethod_virt;
578 struct
580 short int id;
581 short int attribute;
582 unsigned int type;
583 unsigned char name[1];
584 } onemethod32;
585 struct
587 short int id;
588 short int attribute;
589 unsigned int type;
590 unsigned int vtab_offset;
591 unsigned char name[1];
592 } onemethod32_virt;
594 struct
596 short int id;
597 short int type;
598 unsigned int offset;
599 } vfuncoff;
601 struct
603 short int id;
604 short int _pad0;
605 unsigned int type;
606 unsigned int offset;
607 } vfuncoff32;
609 struct
611 short int id;
612 short int attribute;
613 short int index;
614 unsigned char name[1];
615 } nesttypeex;
617 struct
619 short int id;
620 short int attribute;
621 unsigned int index;
622 unsigned char name[1];
623 } nesttypeex32;
625 struct
627 short int id;
628 short int attribute;
629 unsigned int type;
630 unsigned char name[1];
631 } membermodify;
634 #define S_COMPILE 0x0001
635 #define S_REGISTER 0x0002
636 #define S_CONSTANT 0x0003
637 #define S_UDT 0x0004
638 #define S_SSEARCH 0x0005
639 #define S_END 0x0006
640 #define S_SKIP 0x0007
641 #define S_CVRESERVE 0x0008
642 #define S_OBJNAME 0x0009
643 #define S_ENDARG 0x000a
644 #define S_COBOLUDT 0x000b
645 #define S_MANYREG 0x000c
646 #define S_RETURN 0x000d
647 #define S_ENTRYTHIS 0x000e
649 #define S_BPREL 0x0200
650 #define S_LDATA 0x0201
651 #define S_GDATA 0x0202
652 #define S_PUB 0x0203
653 #define S_LPROC 0x0204
654 #define S_GPROC 0x0205
655 #define S_THUNK 0x0206
656 #define S_BLOCK 0x0207
657 #define S_WITH 0x0208
658 #define S_LABEL 0x0209
659 #define S_CEXMODEL 0x020a
660 #define S_VFTPATH 0x020b
661 #define S_REGREL 0x020c
662 #define S_LTHREAD 0x020d
663 #define S_GTHREAD 0x020e
665 #define S_PROCREF 0x0400
666 #define S_DATAREF 0x0401
667 #define S_ALIGN 0x0402
668 #define S_LPROCREF 0x0403
670 #define S_REGISTER_32 0x1001 /* Variants with new 32-bit type indices */
671 #define S_CONSTANT_32 0x1002
672 #define S_UDT_32 0x1003
673 #define S_COBOLUDT_32 0x1004
674 #define S_MANYREG_32 0x1005
676 #define S_BPREL_32 0x1006
677 #define S_LDATA_32 0x1007
678 #define S_GDATA_32 0x1008
679 #define S_PUB_32 0x1009
680 #define S_LPROC_32 0x100a
681 #define S_GPROC_32 0x100b
682 #define S_VFTTABLE_32 0x100c
683 #define S_REGREL_32 0x100d
684 #define S_LTHREAD_32 0x100e
685 #define S_GTHREAD_32 0x100f
689 * This covers the basic datatypes that VC++ seems to be using these days.
690 * 32 bit mode only. There are additional numbers for the pointers in 16
691 * bit mode. There are many other types listed in the documents, but these
692 * are apparently not used by the compiler, or represent pointer types
693 * that are not used.
695 #define T_NOTYPE 0x0000 /* Notype */
696 #define T_ABS 0x0001 /* Abs */
697 #define T_VOID 0x0003 /* Void */
698 #define T_CHAR 0x0010 /* signed char */
699 #define T_SHORT 0x0011 /* short */
700 #define T_LONG 0x0012 /* long */
701 #define T_QUAD 0x0013 /* long long */
702 #define T_UCHAR 0x0020 /* unsigned char */
703 #define T_USHORT 0x0021 /* unsigned short */
704 #define T_ULONG 0x0022 /* unsigned long */
705 #define T_UQUAD 0x0023 /* unsigned long long */
706 #define T_REAL32 0x0040 /* float */
707 #define T_REAL64 0x0041 /* double */
708 #define T_RCHAR 0x0070 /* real char */
709 #define T_WCHAR 0x0071 /* wide char */
710 #define T_INT4 0x0074 /* int */
711 #define T_UINT4 0x0075 /* unsigned int */
713 #define T_32PVOID 0x0403 /* 32 bit near pointer to void */
714 #define T_32PCHAR 0x0410 /* 16:32 near pointer to signed char */
715 #define T_32PSHORT 0x0411 /* 16:32 near pointer to short */
716 #define T_32PLONG 0x0412 /* 16:32 near pointer to int */
717 #define T_32PQUAD 0x0413 /* 16:32 near pointer to long long */
718 #define T_32PUCHAR 0x0420 /* 16:32 near pointer to unsigned char */
719 #define T_32PUSHORT 0x0421 /* 16:32 near pointer to unsigned short */
720 #define T_32PULONG 0x0422 /* 16:32 near pointer to unsigned int */
721 #define T_32PUQUAD 0x0423 /* 16:32 near pointer to long long */
722 #define T_32PREAL32 0x0440 /* 16:32 near pointer to float */
723 #define T_32PREAL64 0x0441 /* 16:32 near pointer to float */
724 #define T_32PRCHAR 0x0470 /* 16:32 near pointer to real char */
725 #define T_32PWCHAR 0x0471 /* 16:32 near pointer to real char */
726 #define T_32PINT4 0x0474 /* 16:32 near pointer to int */
727 #define T_32PUINT4 0x0475 /* 16:32 near pointer to unsigned int */
729 #define LF_MODIFIER 0x0001
730 #define LF_POINTER 0x0002
731 #define LF_ARRAY 0x0003
732 #define LF_CLASS 0x0004
733 #define LF_STRUCTURE 0x0005
734 #define LF_UNION 0x0006
735 #define LF_ENUM 0x0007
736 #define LF_PROCEDURE 0x0008
737 #define LF_MFUNCTION 0x0009
738 #define LF_VTSHAPE 0x000a
739 #define LF_COBOL0 0x000b
740 #define LF_COBOL1 0x000c
741 #define LF_BARRAY 0x000d
742 #define LF_LABEL 0x000e
743 #define LF_NULL 0x000f
744 #define LF_NOTTRAN 0x0010
745 #define LF_DIMARRAY 0x0011
746 #define LF_VFTPATH 0x0012
747 #define LF_PRECOMP 0x0013
748 #define LF_ENDPRECOMP 0x0014
749 #define LF_OEM 0x0015
750 #define LF_TYPESERVER 0x0016
752 #define LF_MODIFIER_32 0x1001 /* variants with new 32-bit type indices */
753 #define LF_POINTER_32 0x1002
754 #define LF_ARRAY_32 0x1003
755 #define LF_CLASS_32 0x1004
756 #define LF_STRUCTURE_32 0x1005
757 #define LF_UNION_32 0x1006
758 #define LF_ENUM_32 0x1007
759 #define LF_PROCEDURE_32 0x1008
760 #define LF_MFUNCTION_32 0x1009
761 #define LF_COBOL0_32 0x100a
762 #define LF_BARRAY_32 0x100b
763 #define LF_DIMARRAY_32 0x100c
764 #define LF_VFTPATH_32 0x100d
765 #define LF_PRECOMP_32 0x100e
766 #define LF_OEM_32 0x100f
768 #define LF_SKIP 0x0200
769 #define LF_ARGLIST 0x0201
770 #define LF_DEFARG 0x0202
771 #define LF_LIST 0x0203
772 #define LF_FIELDLIST 0x0204
773 #define LF_DERIVED 0x0205
774 #define LF_BITFIELD 0x0206
775 #define LF_METHODLIST 0x0207
776 #define LF_DIMCONU 0x0208
777 #define LF_DIMCONLU 0x0209
778 #define LF_DIMVARU 0x020a
779 #define LF_DIMVARLU 0x020b
780 #define LF_REFSYM 0x020c
782 #define LF_SKIP_32 0x1200 /* variants with new 32-bit type indices */
783 #define LF_ARGLIST_32 0x1201
784 #define LF_DEFARG_32 0x1202
785 #define LF_FIELDLIST_32 0x1203
786 #define LF_DERIVED_32 0x1204
787 #define LF_BITFIELD_32 0x1205
788 #define LF_METHODLIST_32 0x1206
789 #define LF_DIMCONU_32 0x1207
790 #define LF_DIMCONLU_32 0x1208
791 #define LF_DIMVARU_32 0x1209
792 #define LF_DIMVARLU_32 0x120a
794 #define LF_BCLASS 0x0400
795 #define LF_VBCLASS 0x0401
796 #define LF_IVBCLASS 0x0402
797 #define LF_ENUMERATE 0x0403
798 #define LF_FRIENDFCN 0x0404
799 #define LF_INDEX 0x0405
800 #define LF_MEMBER 0x0406
801 #define LF_STMEMBER 0x0407
802 #define LF_METHOD 0x0408
803 #define LF_NESTTYPE 0x0409
804 #define LF_VFUNCTAB 0x040a
805 #define LF_FRIENDCLS 0x040b
806 #define LF_ONEMETHOD 0x040c
807 #define LF_VFUNCOFF 0x040d
808 #define LF_NESTTYPEEX 0x040e
809 #define LF_MEMBERMODIFY 0x040f
811 #define LF_BCLASS_32 0x1400 /* variants with new 32-bit type indices */
812 #define LF_VBCLASS_32 0x1401
813 #define LF_IVBCLASS_32 0x1402
814 #define LF_FRIENDFCN_32 0x1403
815 #define LF_INDEX_32 0x1404
816 #define LF_MEMBER_32 0x1405
817 #define LF_STMEMBER_32 0x1406
818 #define LF_METHOD_32 0x1407
819 #define LF_NESTTYPE_32 0x1408
820 #define LF_VFUNCTAB_32 0x1409
821 #define LF_FRIENDCLS_32 0x140a
822 #define LF_ONEMETHOD_32 0x140b
823 #define LF_VFUNCOFF_32 0x140c
824 #define LF_NESTTYPEEX_32 0x140d
826 #define LF_NUMERIC 0x8000 /* numeric leaf types */
827 #define LF_CHAR 0x8000
828 #define LF_SHORT 0x8001
829 #define LF_USHORT 0x8002
830 #define LF_LONG 0x8003
831 #define LF_ULONG 0x8004
832 #define LF_REAL32 0x8005
833 #define LF_REAL64 0x8006
834 #define LF_REAL80 0x8007
835 #define LF_REAL128 0x8008
836 #define LF_QUADWORD 0x8009
837 #define LF_UQUADWORD 0x800a
838 #define LF_REAL48 0x800b
839 #define LF_COMPLEX32 0x800c
840 #define LF_COMPLEX64 0x800d
841 #define LF_COMPLEX80 0x800e
842 #define LF_COMPLEX128 0x800f
843 #define LF_VARSTRING 0x8010
847 #define MAX_BUILTIN_TYPES 0x480
848 static struct datatype * cv_basic_types[MAX_BUILTIN_TYPES];
849 static int num_cv_defined_types = 0;
850 static struct datatype **cv_defined_types = NULL;
853 * For the type CODEVIEW debug directory entries, the debug directory
854 * points to a structure like this. The cv_name field is the name
855 * of an external .PDB file.
857 struct CodeViewDebug
859 char cv_nbtype[8];
860 unsigned int cv_timestamp;
861 char cv_unknown[4];
862 char cv_name[1];
865 struct MiscDebug {
866 unsigned int DataType;
867 unsigned int Length;
868 char Unicode;
869 char Reserved[3];
870 char Data[1];
874 * This is the header that the COFF variety of debug header points to.
876 struct CoffDebug {
877 unsigned int N_Sym;
878 unsigned int SymbolOffset;
879 unsigned int N_Linenum;
880 unsigned int LinenumberOffset;
881 unsigned int Unused[4];
884 struct CoffLinenum {
885 unsigned int VirtualAddr;
886 unsigned short int Linenum;
889 struct CoffFiles {
890 unsigned int startaddr;
891 unsigned int endaddr;
892 char * filename;
893 int linetab_offset;
894 int linecnt;
895 struct name_hash **entries;
896 int neps;
897 int neps_alloc;
901 struct CoffSymbol {
902 union {
903 char ShortName[8];
904 struct {
905 unsigned int NotLong;
906 unsigned int StrTaboff;
907 } Name;
908 } N;
909 unsigned int Value;
910 short SectionNumber;
911 short Type;
912 char StorageClass;
913 unsigned char NumberOfAuxSymbols;
916 struct CoffAuxSection{
917 unsigned int Length;
918 unsigned short NumberOfRelocations;
919 unsigned short NumberOfLinenumbers;
920 unsigned int CheckSum;
921 short Number;
922 char Selection;
923 } Section;
926 * These two structures are used in the directory within a .DBG file
927 * to locate the individual important bits that we might want to see.
929 struct CV4_DirHead {
930 short unsigned int dhsize;
931 short unsigned int desize;
932 unsigned int ndir;
933 unsigned int next_offset;
934 unsigned int flags;
937 struct CV4_DirEnt {
938 short unsigned int subsect_number;
939 short unsigned int module_number;
940 unsigned int offset;
941 unsigned int size;
945 * These are the values of interest that the subsect_number field takes.
947 #define sstAlignSym 0x125
948 #define sstSrcModule 0x127
950 struct codeview_linetab_hdr
952 unsigned int nline;
953 unsigned int segno;
954 unsigned int start;
955 unsigned int end;
956 char * sourcefile;
957 unsigned short * linetab;
958 unsigned int * offtab;
964 * CodeView type information parsing
967 static int
968 numeric_leaf( int *value, unsigned short int *leaf )
970 unsigned short int type = *leaf++;
971 int length = 2;
973 if ( type < LF_NUMERIC )
975 *value = type;
977 else
979 switch ( type )
981 case LF_CHAR:
982 length += 1;
983 *value = *(char *)leaf;
984 break;
986 case LF_SHORT:
987 length += 2;
988 *value = *(short *)leaf;
989 break;
991 case LF_USHORT:
992 length += 2;
993 *value = *(unsigned short *)leaf;
994 break;
996 case LF_LONG:
997 length += 4;
998 *value = *(int *)leaf;
999 break;
1001 case LF_ULONG:
1002 length += 4;
1003 *value = *(unsigned int *)leaf;
1004 break;
1006 case LF_QUADWORD:
1007 case LF_UQUADWORD:
1008 length += 8;
1009 *value = 0; /* FIXME */
1010 break;
1012 case LF_REAL32:
1013 length += 4;
1014 *value = 0; /* FIXME */
1015 break;
1017 case LF_REAL48:
1018 length += 6;
1019 *value = 0; /* FIXME */
1020 break;
1022 case LF_REAL64:
1023 length += 8;
1024 *value = 0; /* FIXME */
1025 break;
1027 case LF_REAL80:
1028 length += 10;
1029 *value = 0; /* FIXME */
1030 break;
1032 case LF_REAL128:
1033 length += 16;
1034 *value = 0; /* FIXME */
1035 break;
1037 case LF_COMPLEX32:
1038 length += 4;
1039 *value = 0; /* FIXME */
1040 break;
1042 case LF_COMPLEX64:
1043 length += 8;
1044 *value = 0; /* FIXME */
1045 break;
1047 case LF_COMPLEX80:
1048 length += 10;
1049 *value = 0; /* FIXME */
1050 break;
1052 case LF_COMPLEX128:
1053 length += 16;
1054 *value = 0; /* FIXME */
1055 break;
1057 case LF_VARSTRING:
1058 length += 2 + *leaf;
1059 *value = 0; /* FIXME */
1060 break;
1062 default:
1063 DEBUG_Printf( DBG_CHN_MESG, "Unknown numeric leaf type %04x\n", type );
1064 *value = 0;
1065 break;
1069 return length;
1072 static char *
1073 terminate_string( unsigned char *name )
1075 static char symname[256];
1077 int namelen = name[0];
1078 assert( namelen >= 0 && namelen < 256 );
1080 memcpy( symname, name+1, namelen );
1081 symname[namelen] = '\0';
1083 if ( !*symname || strcmp( symname, "__unnamed" ) == 0 )
1084 return NULL;
1085 else
1086 return symname;
1089 static
1090 struct datatype * DEBUG_GetCVType(unsigned int typeno)
1092 struct datatype * dt = NULL;
1095 * Convert Codeview type numbers into something we can grok internally.
1096 * Numbers < 0x1000 are all fixed builtin types. Numbers from 0x1000 and
1097 * up are all user defined (structs, etc).
1099 if ( typeno < 0x1000 )
1101 if ( typeno < MAX_BUILTIN_TYPES )
1102 dt = cv_basic_types[typeno];
1104 else
1106 if ( typeno - 0x1000 < num_cv_defined_types )
1107 dt = cv_defined_types[typeno - 0x1000];
1110 return dt;
1113 static int
1114 DEBUG_AddCVType( unsigned int typeno, struct datatype *dt )
1116 while ( typeno - 0x1000 >= num_cv_defined_types )
1118 num_cv_defined_types += 0x100;
1119 cv_defined_types = (struct datatype **)
1120 DBG_realloc( cv_defined_types,
1121 num_cv_defined_types * sizeof(struct datatype *) );
1123 memset( cv_defined_types + num_cv_defined_types - 0x100,
1125 0x100 * sizeof(struct datatype *) );
1127 if ( cv_defined_types == NULL )
1128 return FALSE;
1131 cv_defined_types[ typeno - 0x1000 ] = dt;
1132 return TRUE;
1135 static void
1136 DEBUG_ClearTypeTable( void )
1138 if ( cv_defined_types )
1139 DBG_free( cv_defined_types );
1141 cv_defined_types = NULL;
1142 num_cv_defined_types = 0;
1145 static int
1146 DEBUG_AddCVType_Pointer( unsigned int typeno, unsigned int datatype )
1148 struct datatype *dt =
1149 DEBUG_FindOrMakePointerType( DEBUG_GetCVType( datatype ) );
1151 return DEBUG_AddCVType( typeno, dt );
1154 static int
1155 DEBUG_AddCVType_Array( unsigned int typeno, char *name,
1156 unsigned int elemtype, unsigned int arr_len )
1158 struct datatype *dt = DEBUG_NewDataType( DT_ARRAY, name );
1159 struct datatype *elem = DEBUG_GetCVType( elemtype );
1160 unsigned int elem_size = elem? DEBUG_GetObjectSize( elem ) : 0;
1161 unsigned int arr_max = elem_size? arr_len / elem_size : 0;
1163 DEBUG_SetArrayParams( dt, 0, arr_max, elem );
1164 return DEBUG_AddCVType( typeno, dt );
1167 static int
1168 DEBUG_AddCVType_Bitfield( unsigned int typeno,
1169 unsigned int bitoff, unsigned int nbits,
1170 unsigned int basetype )
1172 struct datatype *dt = DEBUG_NewDataType( DT_BITFIELD, NULL );
1173 struct datatype *base = DEBUG_GetCVType( basetype );
1175 DEBUG_SetBitfieldParams( dt, bitoff, nbits, base );
1176 return DEBUG_AddCVType( typeno, dt );
1179 static int
1180 DEBUG_AddCVType_EnumFieldList( unsigned int typeno, unsigned char *list, int len )
1182 struct datatype *dt = DEBUG_NewDataType( DT_ENUM, NULL );
1183 unsigned char *ptr = list;
1185 while ( ptr - list < len )
1187 union codeview_fieldtype *type = (union codeview_fieldtype *)ptr;
1189 if ( *ptr >= 0xf0 ) /* LF_PAD... */
1191 ptr += *ptr & 0x0f;
1192 continue;
1195 switch ( type->generic.id )
1197 case LF_ENUMERATE:
1199 int value, vlen = numeric_leaf( &value, &type->enumerate.value );
1200 unsigned char *name = (unsigned char *)&type->enumerate.value + vlen;
1202 DEBUG_AddStructElement( dt, terminate_string( name ),
1203 NULL, value, 0 );
1205 ptr += 2 + 2 + vlen + (1 + name[0]);
1206 break;
1209 default:
1210 DEBUG_Printf( DBG_CHN_MESG, "Unhandled type %04x in ENUM field list\n",
1211 type->generic.id );
1212 return FALSE;
1216 return DEBUG_AddCVType( typeno, dt );
1219 static int
1220 DEBUG_AddCVType_StructFieldList( unsigned int typeno, unsigned char *list, int len )
1222 struct datatype *dt = DEBUG_NewDataType( DT_STRUCT, NULL );
1223 unsigned char *ptr = list;
1225 while ( ptr - list < len )
1227 union codeview_fieldtype *type = (union codeview_fieldtype *)ptr;
1229 if ( *ptr >= 0xf0 ) /* LF_PAD... */
1231 ptr += *ptr & 0x0f;
1232 continue;
1235 switch ( type->generic.id )
1237 case LF_BCLASS:
1239 int offset, olen = numeric_leaf( &offset, &type->bclass.offset );
1241 /* FIXME: ignored for now */
1243 ptr += 2 + 2 + 2 + olen;
1244 break;
1247 case LF_BCLASS_32:
1249 int offset, olen = numeric_leaf( &offset, &type->bclass32.offset );
1251 /* FIXME: ignored for now */
1253 ptr += 2 + 2 + 4 + olen;
1254 break;
1257 case LF_VBCLASS:
1258 case LF_IVBCLASS:
1260 int vbpoff, vbplen = numeric_leaf( &vbpoff, &type->vbclass.vbpoff );
1261 unsigned short int *p_vboff = (unsigned short int *)((char *)&type->vbclass.vbpoff + vbpoff);
1262 int vpoff, vplen = numeric_leaf( &vpoff, p_vboff );
1264 /* FIXME: ignored for now */
1266 ptr += 2 + 2 + 2 + 2 + vbplen + vplen;
1267 break;
1270 case LF_VBCLASS_32:
1271 case LF_IVBCLASS_32:
1273 int vbpoff, vbplen = numeric_leaf( &vbpoff, &type->vbclass32.vbpoff );
1274 unsigned short int *p_vboff = (unsigned short int *)((char *)&type->vbclass32.vbpoff + vbpoff);
1275 int vpoff, vplen = numeric_leaf( &vpoff, p_vboff );
1277 /* FIXME: ignored for now */
1279 ptr += 2 + 2 + 4 + 4 + vbplen + vplen;
1280 break;
1283 case LF_MEMBER:
1285 int offset, olen = numeric_leaf( &offset, &type->member.offset );
1286 unsigned char *name = (unsigned char *)&type->member.offset + olen;
1288 struct datatype *subtype = DEBUG_GetCVType( type->member.type );
1289 int elem_size = subtype? DEBUG_GetObjectSize( subtype ) : 0;
1291 DEBUG_AddStructElement( dt, terminate_string( name ),
1292 subtype, offset << 3, elem_size << 3 );
1294 ptr += 2 + 2 + 2 + olen + (1 + name[0]);
1295 break;
1298 case LF_MEMBER_32:
1300 int offset, olen = numeric_leaf( &offset, &type->member32.offset );
1301 unsigned char *name = (unsigned char *)&type->member32.offset + olen;
1303 struct datatype *subtype = DEBUG_GetCVType( type->member32.type );
1304 int elem_size = subtype? DEBUG_GetObjectSize( subtype ) : 0;
1306 DEBUG_AddStructElement( dt, terminate_string( name ),
1307 subtype, offset << 3, elem_size << 3 );
1309 ptr += 2 + 2 + 4 + olen + (1 + name[0]);
1310 break;
1313 case LF_STMEMBER:
1314 /* FIXME: ignored for now */
1315 ptr += 2 + 2 + 2 + (1 + type->stmember.name[0]);
1316 break;
1318 case LF_STMEMBER_32:
1319 /* FIXME: ignored for now */
1320 ptr += 2 + 4 + 2 + (1 + type->stmember32.name[0]);
1321 break;
1323 case LF_METHOD:
1324 /* FIXME: ignored for now */
1325 ptr += 2 + 2 + 2 + (1 + type->method.name[0]);
1326 break;
1328 case LF_METHOD_32:
1329 /* FIXME: ignored for now */
1330 ptr += 2 + 2 + 4 + (1 + type->method32.name[0]);
1331 break;
1333 case LF_NESTTYPE:
1334 /* FIXME: ignored for now */
1335 ptr += 2 + 2 + (1 + type->nesttype.name[0]);
1336 break;
1338 case LF_NESTTYPE_32:
1339 /* FIXME: ignored for now */
1340 ptr += 2 + 2 + 4 + (1 + type->nesttype32.name[0]);
1341 break;
1343 case LF_VFUNCTAB:
1344 /* FIXME: ignored for now */
1345 ptr += 2 + 2;
1346 break;
1348 case LF_VFUNCTAB_32:
1349 /* FIXME: ignored for now */
1350 ptr += 2 + 2 + 4;
1351 break;
1353 case LF_ONEMETHOD:
1354 /* FIXME: ignored for now */
1355 switch ( (type->onemethod.attribute >> 2) & 7 )
1357 case 4: case 6: /* (pure) introducing virtual method */
1358 ptr += 2 + 2 + 2 + 4 + (1 + type->onemethod_virt.name[0]);
1359 break;
1361 default:
1362 ptr += 2 + 2 + 2 + (1 + type->onemethod.name[0]);
1363 break;
1365 break;
1367 case LF_ONEMETHOD_32:
1368 /* FIXME: ignored for now */
1369 switch ( (type->onemethod32.attribute >> 2) & 7 )
1371 case 4: case 6: /* (pure) introducing virtual method */
1372 ptr += 2 + 2 + 4 + 4 + (1 + type->onemethod32_virt.name[0]);
1373 break;
1375 default:
1376 ptr += 2 + 2 + 4 + (1 + type->onemethod32.name[0]);
1377 break;
1379 break;
1381 default:
1382 DEBUG_Printf( DBG_CHN_MESG, "Unhandled type %04x in STRUCT field list\n",
1383 type->generic.id );
1384 return FALSE;
1388 return DEBUG_AddCVType( typeno, dt );
1391 static int
1392 DEBUG_AddCVType_Enum( unsigned int typeno, char *name, unsigned int fieldlist )
1394 struct datatype *dt = DEBUG_NewDataType( DT_ENUM, name );
1395 struct datatype *list = DEBUG_GetCVType( fieldlist );
1397 if ( list )
1398 DEBUG_CopyFieldlist( dt, list );
1400 return DEBUG_AddCVType( typeno, dt );
1403 static int
1404 DEBUG_AddCVType_Struct( unsigned int typeno, char *name, int structlen, unsigned int fieldlist )
1406 struct datatype *dt = DEBUG_NewDataType( DT_STRUCT, name );
1407 struct datatype *list = DEBUG_GetCVType( fieldlist );
1409 if ( list )
1411 DEBUG_SetStructSize( dt, structlen );
1412 DEBUG_CopyFieldlist( dt, list );
1415 return DEBUG_AddCVType( typeno, dt );
1418 static int
1419 DEBUG_ParseTypeTable( char *table, int len )
1421 unsigned int curr_type = 0x1000;
1422 char *ptr = table;
1424 while ( ptr - table < len )
1426 union codeview_type *type = (union codeview_type *) ptr;
1427 int retv = TRUE;
1429 switch ( type->generic.id )
1431 case LF_POINTER:
1432 retv = DEBUG_AddCVType_Pointer( curr_type, type->pointer.datatype );
1433 break;
1434 case LF_POINTER_32:
1435 retv = DEBUG_AddCVType_Pointer( curr_type, type->pointer32.datatype );
1436 break;
1438 case LF_ARRAY:
1440 int arrlen, alen = numeric_leaf( &arrlen, &type->array.arrlen );
1441 unsigned char *name = (unsigned char *)&type->array.arrlen + alen;
1443 retv = DEBUG_AddCVType_Array( curr_type, terminate_string( name ),
1444 type->array.elemtype, arrlen );
1445 break;
1447 case LF_ARRAY_32:
1449 int arrlen, alen = numeric_leaf( &arrlen, &type->array32.arrlen );
1450 unsigned char *name = (unsigned char *)&type->array32.arrlen + alen;
1452 retv = DEBUG_AddCVType_Array( curr_type, terminate_string( name ),
1453 type->array32.elemtype, type->array32.arrlen );
1454 break;
1457 case LF_BITFIELD:
1458 retv = DEBUG_AddCVType_Bitfield( curr_type, type->bitfield.bitoff,
1459 type->bitfield.nbits,
1460 type->bitfield.type );
1461 break;
1462 case LF_BITFIELD_32:
1463 retv = DEBUG_AddCVType_Bitfield( curr_type, type->bitfield32.bitoff,
1464 type->bitfield32.nbits,
1465 type->bitfield32.type );
1466 break;
1468 case LF_FIELDLIST:
1469 case LF_FIELDLIST_32:
1472 * A 'field list' is a CodeView-specific data type which doesn't
1473 * directly correspond to any high-level data type. It is used
1474 * to hold the collection of members of a struct, class, union
1475 * or enum type. The actual definition of that type will follow
1476 * later, and refer to the field list definition record.
1478 * As we don't have a field list type ourselves, we look ahead
1479 * in the field list to try to find out whether this field list
1480 * will be used for an enum or struct type, and create a dummy
1481 * type of the corresponding sort. Later on, the definition of
1482 * the 'real' type will copy the member / enumeration data.
1485 char *list = type->fieldlist.list;
1486 int len = (ptr + type->generic.len + 2) - list;
1488 if ( ((union codeview_fieldtype *)list)->generic.id == LF_ENUMERATE )
1489 retv = DEBUG_AddCVType_EnumFieldList( curr_type, list, len );
1490 else
1491 retv = DEBUG_AddCVType_StructFieldList( curr_type, list, len );
1492 break;
1495 case LF_STRUCTURE:
1496 case LF_CLASS:
1498 int structlen, slen = numeric_leaf( &structlen, &type->structure.structlen );
1499 unsigned char *name = (unsigned char *)&type->structure.structlen + slen;
1501 retv = DEBUG_AddCVType_Struct( curr_type, terminate_string( name ),
1502 structlen, type->structure.fieldlist );
1503 break;
1505 case LF_STRUCTURE_32:
1506 case LF_CLASS_32:
1508 int structlen, slen = numeric_leaf( &structlen, &type->structure32.structlen );
1509 unsigned char *name = (unsigned char *)&type->structure32.structlen + slen;
1511 retv = DEBUG_AddCVType_Struct( curr_type, terminate_string( name ),
1512 structlen, type->structure32.fieldlist );
1513 break;
1516 case LF_UNION:
1518 int un_len, ulen = numeric_leaf( &un_len, &type->t_union.un_len );
1519 unsigned char *name = (unsigned char *)&type->t_union.un_len + ulen;
1521 retv = DEBUG_AddCVType_Struct( curr_type, terminate_string( name ),
1522 un_len, type->t_union.fieldlist );
1523 break;
1525 case LF_UNION_32:
1527 int un_len, ulen = numeric_leaf( &un_len, &type->t_union32.un_len );
1528 unsigned char *name = (unsigned char *)&type->t_union32.un_len + ulen;
1530 retv = DEBUG_AddCVType_Struct( curr_type, terminate_string( name ),
1531 un_len, type->t_union32.fieldlist );
1532 break;
1535 case LF_ENUM:
1536 retv = DEBUG_AddCVType_Enum( curr_type, terminate_string( type->enumeration.name ),
1537 type->enumeration.field );
1538 break;
1539 case LF_ENUM_32:
1540 retv = DEBUG_AddCVType_Enum( curr_type, terminate_string( type->enumeration32.name ),
1541 type->enumeration32.field );
1542 break;
1544 default:
1545 break;
1548 if ( !retv )
1549 return FALSE;
1551 curr_type++;
1552 ptr += type->generic.len + 2;
1555 return TRUE;
1559 void
1560 DEBUG_InitCVDataTypes(void)
1563 * These are the common builtin types that are used by VC++.
1565 cv_basic_types[T_NOTYPE] = NULL;
1566 cv_basic_types[T_ABS] = NULL;
1567 cv_basic_types[T_VOID] = DEBUG_NewDataType(DT_BASIC, "void");
1568 cv_basic_types[T_CHAR] = DEBUG_NewDataType(DT_BASIC, "char");
1569 cv_basic_types[T_SHORT] = DEBUG_NewDataType(DT_BASIC, "short int");
1570 cv_basic_types[T_LONG] = DEBUG_NewDataType(DT_BASIC, "long int");
1571 cv_basic_types[T_QUAD] = DEBUG_NewDataType(DT_BASIC, "long long int");
1572 cv_basic_types[T_UCHAR] = DEBUG_NewDataType(DT_BASIC, "unsigned char");
1573 cv_basic_types[T_USHORT] = DEBUG_NewDataType(DT_BASIC, "short unsigned int");
1574 cv_basic_types[T_ULONG] = DEBUG_NewDataType(DT_BASIC, "long unsigned int");
1575 cv_basic_types[T_UQUAD] = DEBUG_NewDataType(DT_BASIC, "long long unsigned int");
1576 cv_basic_types[T_REAL32] = DEBUG_NewDataType(DT_BASIC, "float");
1577 cv_basic_types[T_REAL64] = DEBUG_NewDataType(DT_BASIC, "double");
1578 cv_basic_types[T_RCHAR] = DEBUG_NewDataType(DT_BASIC, "char");
1579 cv_basic_types[T_WCHAR] = DEBUG_NewDataType(DT_BASIC, "short");
1580 cv_basic_types[T_INT4] = DEBUG_NewDataType(DT_BASIC, "int");
1581 cv_basic_types[T_UINT4] = DEBUG_NewDataType(DT_BASIC, "unsigned int");
1583 cv_basic_types[T_32PVOID] = DEBUG_FindOrMakePointerType(cv_basic_types[T_VOID]);
1584 cv_basic_types[T_32PCHAR] = DEBUG_FindOrMakePointerType(cv_basic_types[T_CHAR]);
1585 cv_basic_types[T_32PSHORT] = DEBUG_FindOrMakePointerType(cv_basic_types[T_SHORT]);
1586 cv_basic_types[T_32PLONG] = DEBUG_FindOrMakePointerType(cv_basic_types[T_LONG]);
1587 cv_basic_types[T_32PQUAD] = DEBUG_FindOrMakePointerType(cv_basic_types[T_QUAD]);
1588 cv_basic_types[T_32PUCHAR] = DEBUG_FindOrMakePointerType(cv_basic_types[T_UCHAR]);
1589 cv_basic_types[T_32PUSHORT] = DEBUG_FindOrMakePointerType(cv_basic_types[T_USHORT]);
1590 cv_basic_types[T_32PULONG] = DEBUG_FindOrMakePointerType(cv_basic_types[T_ULONG]);
1591 cv_basic_types[T_32PUQUAD] = DEBUG_FindOrMakePointerType(cv_basic_types[T_UQUAD]);
1592 cv_basic_types[T_32PREAL32] = DEBUG_FindOrMakePointerType(cv_basic_types[T_REAL32]);
1593 cv_basic_types[T_32PREAL64] = DEBUG_FindOrMakePointerType(cv_basic_types[T_REAL64]);
1594 cv_basic_types[T_32PRCHAR] = DEBUG_FindOrMakePointerType(cv_basic_types[T_RCHAR]);
1595 cv_basic_types[T_32PWCHAR] = DEBUG_FindOrMakePointerType(cv_basic_types[T_WCHAR]);
1596 cv_basic_types[T_32PINT4] = DEBUG_FindOrMakePointerType(cv_basic_types[T_INT4]);
1597 cv_basic_types[T_32PUINT4] = DEBUG_FindOrMakePointerType(cv_basic_types[T_UINT4]);
1601 * In this function, we keep track of deferred debugging information
1602 * that we may need later if we were to need to use the internal debugger.
1603 * We don't fully process it here for performance reasons.
1606 DEBUG_RegisterMSCDebugInfo(DBG_MODULE* module, HANDLE hFile, void* _nth, unsigned long nth_ofs)
1608 int has_codeview = FALSE;
1609 int rtn = FALSE;
1610 IMAGE_DEBUG_DIRECTORY dbg;
1611 u_long v_addr, size, orig_size;
1612 PIMAGE_NT_HEADERS nth = (PIMAGE_NT_HEADERS)_nth;
1614 orig_size = nth->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].Size;
1615 if (orig_size) {
1616 v_addr = nth->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress;
1617 for(size = orig_size; size >= sizeof(dbg); size -= sizeof(dbg))
1619 if (!DEBUG_READ_MEM_VERBOSE((void*)((char *) module->load_addr + v_addr), &dbg, sizeof(dbg))) continue;
1621 switch(dbg.Type)
1623 case IMAGE_DEBUG_TYPE_CODEVIEW:
1624 case IMAGE_DEBUG_TYPE_MISC:
1625 has_codeview = TRUE;
1626 break;
1628 v_addr += sizeof(dbg);
1631 v_addr = nth->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress;
1632 for(size = orig_size; size >= sizeof(dbg); size -= sizeof(dbg))
1634 if (!DEBUG_READ_MEM_VERBOSE((void*)((char *)module->load_addr + v_addr), &dbg, sizeof(dbg))) continue;
1636 switch(dbg.Type)
1638 case IMAGE_DEBUG_TYPE_COFF:
1640 * If we have both codeview and COFF debug info, ignore the
1641 * coff debug info as it would just confuse us, and it is
1642 * less complete.
1644 * FIXME - this is broken - if we cannot find the PDB file, then
1645 * we end up with no debugging info at all. In this case, we
1646 * should use the COFF info as a backup.
1648 if( has_codeview )
1650 break;
1652 case IMAGE_DEBUG_TYPE_CODEVIEW:
1653 case IMAGE_DEBUG_TYPE_MISC:
1655 * This is usually an indirection to a .DBG file.
1656 * This is similar to (but a slightly older format) from the
1657 * PDB file.
1659 * First check to see if the image was 'stripped'. If so, it
1660 * means that this entry points to a .DBG file. Otherwise,
1661 * it just points to itself, and we can ignore this.
1664 if( (dbg.Type != IMAGE_DEBUG_TYPE_MISC) ||
1665 (nth->FileHeader.Characteristics & IMAGE_FILE_DEBUG_STRIPPED) != 0 )
1668 * Read the important bits. What we do after this depends
1669 * upon the type, but this is always enough so we are able
1670 * to proceed if we know what we need to do next.
1672 /* basically, the PE loader maps all sections (data, resources...), but doesn't map
1673 * the DataDirectory array's content. One its entry contains the *beloved*
1674 * debug information. (Note the DataDirectory is mapped, not its content)
1676 HANDLE hMap;
1677 char* dbg_info;
1679 DEBUG_Printf(DBG_CHN_TRACE, "PE debugging info at %ld<%ld>\n", dbg.PointerToRawData, dbg.SizeOfData);
1680 dbg_info = DEBUG_MapDebugInfoFile(NULL, dbg.PointerToRawData, dbg.SizeOfData,
1681 &hFile, &hMap);
1683 if (dbg_info != NULL &&
1684 (module->extra_info = DBG_alloc(sizeof(MSC_DBG_INFO))) != NULL) {
1685 MSC_INFO(module)->dbg_info = dbg_info;
1686 MSC_INFO(module)->dbg_size = dbg.SizeOfData;
1687 MSC_INFO(module)->dbgdir = dbg;
1688 MSC_INFO(module)->sect_ofs = nth_ofs + OFFSET_OF(IMAGE_NT_HEADERS, OptionalHeader) +
1689 nth->FileHeader.SizeOfOptionalHeader;
1690 MSC_INFO(module)->nsect = nth->FileHeader.NumberOfSections;
1691 DEBUG_ProcessMSCDebugInfo(module);
1692 DBG_free(MSC_INFO(module));
1693 MSC_INFO(module) = NULL;
1695 DEBUG_UnmapDebugInfoFile(0, hMap, dbg_info);
1697 break;
1698 #if 0
1699 default:
1700 #endif
1702 v_addr += sizeof(dbg);
1704 DEBUG_CurrProcess->next_index++;
1707 return rtn;
1710 /* look for stabs information in PE header (it's how mingw compiler provides its
1711 * debugging information), and also wine PE <-> ELF linking thru .wsolnk sections
1713 int DEBUG_RegisterStabsDebugInfo(DBG_MODULE* module, HANDLE hFile, void* _nth,
1714 unsigned long nth_ofs)
1716 IMAGE_SECTION_HEADER pe_seg;
1717 unsigned long pe_seg_ofs;
1718 int i, stabsize = 0, stabstrsize = 0;
1719 unsigned int stabs = 0, stabstr = 0;
1720 PIMAGE_NT_HEADERS nth = (PIMAGE_NT_HEADERS)_nth;
1722 pe_seg_ofs = nth_ofs + OFFSET_OF(IMAGE_NT_HEADERS, OptionalHeader) +
1723 nth->FileHeader.SizeOfOptionalHeader;
1725 for (i = 0; i < nth->FileHeader.NumberOfSections; i++, pe_seg_ofs += sizeof(pe_seg)) {
1726 if (!DEBUG_READ_MEM_VERBOSE((void*)((char *)module->load_addr + pe_seg_ofs),
1727 &pe_seg, sizeof(pe_seg)))
1728 continue;
1730 if (!strcasecmp(pe_seg.Name, ".stab")) {
1731 stabs = pe_seg.VirtualAddress;
1732 stabsize = pe_seg.SizeOfRawData;
1733 } else if (!strncasecmp(pe_seg.Name, ".stabstr", 8)) {
1734 stabstr = pe_seg.VirtualAddress;
1735 stabstrsize = pe_seg.SizeOfRawData;
1739 if (stabstrsize && stabsize) {
1740 char* s1 = DBG_alloc(stabsize+stabstrsize);
1742 if (s1) {
1743 if (DEBUG_READ_MEM_VERBOSE((char*)module->load_addr + stabs, s1, stabsize) &&
1744 DEBUG_READ_MEM_VERBOSE((char*)module->load_addr + stabstr,
1745 s1 + stabsize, stabstrsize)) {
1746 DEBUG_ParseStabs(s1, 0, 0, stabsize, stabsize, stabstrsize);
1747 } else {
1748 DEBUG_Printf(DBG_CHN_MESG, "couldn't read data block\n");
1750 DBG_free(s1);
1751 } else {
1752 DEBUG_Printf(DBG_CHN_MESG, "couldn't alloc %d bytes\n",
1753 stabsize + stabstrsize);
1756 return TRUE;
1760 * Process COFF debugging information embedded in a Win32 application.
1763 static
1765 DEBUG_ProcessCoff(DBG_MODULE* module)
1767 struct CoffAuxSection * aux;
1768 struct CoffDebug * coff;
1769 struct CoffFiles * coff_files = NULL;
1770 struct CoffLinenum * coff_linetab;
1771 char * coff_strtab;
1772 struct CoffSymbol * coff_sym;
1773 struct CoffSymbol * coff_symbol;
1774 struct CoffFiles * curr_file = NULL;
1775 int i;
1776 int j;
1777 int k;
1778 struct CoffLinenum * linepnt;
1779 int linetab_indx;
1780 char namebuff[9];
1781 char * nampnt;
1782 int naux;
1783 DBG_VALUE new_value;
1784 int nfiles = 0;
1785 int nfiles_alloc = 0;
1786 struct CoffFiles orig_file;
1787 int rtn = FALSE;
1788 char * this_file = NULL;
1790 coff = (struct CoffDebug *) MSC_INFO(module)->dbg_info;
1792 coff_symbol = (struct CoffSymbol *) ((unsigned int) coff + coff->SymbolOffset);
1793 coff_linetab = (struct CoffLinenum *) ((unsigned int) coff + coff->LinenumberOffset);
1794 coff_strtab = (char *) ((unsigned int) coff_symbol + 18*coff->N_Sym);
1796 linetab_indx = 0;
1798 new_value.cookie = DV_TARGET;
1799 new_value.type = NULL;
1801 for(i=0; i < coff->N_Sym; i++ )
1804 * We do this because some compilers (i.e. gcc) incorrectly
1805 * pad the structure up to a 4 byte boundary. The structure
1806 * is really only 18 bytes long, so we have to manually make sure
1807 * we get it right.
1809 * FIXME - there must be a way to have autoconf figure out the
1810 * correct compiler option for this. If it is always gcc, that
1811 * makes life simpler, but I don't want to force this.
1813 coff_sym = (struct CoffSymbol *) ((unsigned int) coff_symbol + 18*i);
1814 naux = coff_sym->NumberOfAuxSymbols;
1816 if( coff_sym->StorageClass == IMAGE_SYM_CLASS_FILE )
1818 if( nfiles + 1 >= nfiles_alloc )
1820 nfiles_alloc += 10;
1821 coff_files = (struct CoffFiles *) DBG_realloc(coff_files,
1822 nfiles_alloc * sizeof(struct CoffFiles));
1824 curr_file = coff_files + nfiles;
1825 nfiles++;
1826 curr_file->startaddr = 0xffffffff;
1827 curr_file->endaddr = 0;
1828 curr_file->filename = ((char *) coff_sym) + 18;
1829 curr_file->linetab_offset = -1;
1830 curr_file->linecnt = 0;
1831 curr_file->entries = NULL;
1832 curr_file->neps = curr_file->neps_alloc = 0;
1833 DEBUG_Printf(DBG_CHN_TRACE,"New file %s\n", curr_file->filename);
1834 i += naux;
1835 continue;
1839 * This guy marks the size and location of the text section
1840 * for the current file. We need to keep track of this so
1841 * we can figure out what file the different global functions
1842 * go with.
1844 if( (coff_sym->StorageClass == IMAGE_SYM_CLASS_STATIC)
1845 && (naux != 0)
1846 && (coff_sym->Type == 0)
1847 && (coff_sym->SectionNumber == 1) )
1849 aux = (struct CoffAuxSection *) ((unsigned int) coff_sym + 18);
1851 if( curr_file->linetab_offset != -1 )
1853 #if 0
1854 DEBUG_Printf(DBG_CHN_TRACE, "Duplicating sect from %s: %x %x %x %d %d\n",
1855 curr_file->filename,
1856 aux->Length,
1857 aux->NumberOfRelocations,
1858 aux->NumberOfLinenumbers,
1859 aux->Number,
1860 aux->Selection);
1861 DEBUG_Printf(DBG_CHN_TRACE, "More sect %d %x %d %d %d\n",
1862 coff_sym->SectionNumber,
1863 coff_sym->Value,
1864 coff_sym->Type,
1865 coff_sym->StorageClass,
1866 coff_sym->NumberOfAuxSymbols);
1867 #endif
1870 * Save this so we can copy bits from it.
1872 orig_file = *curr_file;
1875 * Duplicate the file entry. We have no way to describe
1876 * multiple text sections in our current way of handling things.
1878 if( nfiles + 1 >= nfiles_alloc )
1880 nfiles_alloc += 10;
1881 coff_files = (struct CoffFiles *) DBG_realloc(coff_files,
1882 nfiles_alloc * sizeof(struct CoffFiles));
1884 curr_file = coff_files + nfiles;
1885 nfiles++;
1886 curr_file->startaddr = 0xffffffff;
1887 curr_file->endaddr = 0;
1888 curr_file->filename = orig_file.filename;
1889 curr_file->linetab_offset = -1;
1890 curr_file->linecnt = 0;
1891 curr_file->entries = NULL;
1892 curr_file->neps = curr_file->neps_alloc = 0;
1894 #if 0
1895 else
1897 DEBUG_Printf(DBG_CHN_TRACE, "New text sect from %s: %x %x %x %d %d\n",
1898 curr_file->filename,
1899 aux->Length,
1900 aux->NumberOfRelocations,
1901 aux->NumberOfLinenumbers,
1902 aux->Number,
1903 aux->Selection);
1905 #endif
1907 if( curr_file->startaddr > coff_sym->Value )
1909 curr_file->startaddr = coff_sym->Value;
1912 if( curr_file->startaddr > coff_sym->Value )
1914 curr_file->startaddr = coff_sym->Value;
1917 if( curr_file->endaddr < coff_sym->Value + aux->Length )
1919 curr_file->endaddr = coff_sym->Value + aux->Length;
1922 curr_file->linetab_offset = linetab_indx;
1923 curr_file->linecnt = aux->NumberOfLinenumbers;
1924 linetab_indx += aux->NumberOfLinenumbers;
1925 i += naux;
1926 continue;
1929 if( (coff_sym->StorageClass == IMAGE_SYM_CLASS_STATIC)
1930 && (naux == 0)
1931 && (coff_sym->SectionNumber == 1) )
1934 * This is a normal static function when naux == 0.
1935 * Just register it. The current file is the correct
1936 * one in this instance.
1938 if( coff_sym->N.Name.NotLong )
1940 memcpy(namebuff, coff_sym->N.ShortName, 8);
1941 namebuff[8] = '\0';
1942 nampnt = &namebuff[0];
1944 else
1946 nampnt = coff_strtab + coff_sym->N.Name.StrTaboff;
1949 if( nampnt[0] == '_' )
1951 nampnt++;
1954 new_value.addr.seg = 0;
1955 new_value.addr.off = (int) ((char *)module->load_addr + coff_sym->Value);
1957 if( curr_file->neps + 1 >= curr_file->neps_alloc )
1959 curr_file->neps_alloc += 10;
1960 curr_file->entries = (struct name_hash **)
1961 DBG_realloc(curr_file->entries,
1962 curr_file->neps_alloc * sizeof(struct name_hash *));
1964 #if 0
1965 DEBUG_Printf(DBG_CHN_TRACE,"\tAdding static symbol %s\n", nampnt);
1966 #endif
1967 curr_file->entries[curr_file->neps++] =
1968 DEBUG_AddSymbol( nampnt, &new_value, this_file, SYM_WIN32 );
1969 i += naux;
1970 continue;
1973 if( (coff_sym->StorageClass == IMAGE_SYM_CLASS_EXTERNAL)
1974 && ISFCN(coff_sym->Type)
1975 && (coff_sym->SectionNumber > 0) )
1977 if( coff_sym->N.Name.NotLong )
1979 memcpy(namebuff, coff_sym->N.ShortName, 8);
1980 namebuff[8] = '\0';
1981 nampnt = &namebuff[0];
1983 else
1985 nampnt = coff_strtab + coff_sym->N.Name.StrTaboff;
1989 if( nampnt[0] == '_' )
1991 nampnt++;
1994 new_value.addr.seg = 0;
1995 new_value.addr.off = (int) ((char *)module->load_addr + coff_sym->Value);
1997 #if 0
1998 DEBUG_Printf(DBG_CHN_TRACE, "%d: %x %s\n", i, new_value.addr.off, nampnt);
2000 DEBUG_Printf(DBG_CHN_TRACE,"\tAdding global symbol %s\n", nampnt);
2001 #endif
2004 * Now we need to figure out which file this guy belongs to.
2006 this_file = NULL;
2007 for(j=0; j < nfiles; j++)
2009 if( coff_files[j].startaddr <= coff_sym->Value
2010 && coff_files[j].endaddr > coff_sym->Value )
2012 this_file = coff_files[j].filename;
2013 break;
2016 if( coff_files[j].neps + 1 >= coff_files[j].neps_alloc )
2018 coff_files[j].neps_alloc += 10;
2019 coff_files[j].entries = (struct name_hash **)
2020 DBG_realloc(coff_files[j].entries,
2021 coff_files[j].neps_alloc * sizeof(struct name_hash *));
2023 coff_files[j].entries[coff_files[j].neps++] =
2024 DEBUG_AddSymbol( nampnt, &new_value, this_file, SYM_WIN32 );
2025 i += naux;
2026 continue;
2029 if( (coff_sym->StorageClass == IMAGE_SYM_CLASS_EXTERNAL)
2030 && (coff_sym->SectionNumber > 0) )
2033 * Similar to above, but for the case of data symbols.
2034 * These aren't treated as entrypoints.
2036 if( coff_sym->N.Name.NotLong )
2038 memcpy(namebuff, coff_sym->N.ShortName, 8);
2039 namebuff[8] = '\0';
2040 nampnt = &namebuff[0];
2042 else
2044 nampnt = coff_strtab + coff_sym->N.Name.StrTaboff;
2048 if( nampnt[0] == '_' )
2050 nampnt++;
2053 new_value.addr.seg = 0;
2054 new_value.addr.off = (int) ((char *)module->load_addr + coff_sym->Value);
2056 #if 0
2057 DEBUG_Printf(DBG_CHN_TRACE, "%d: %x %s\n", i, new_value.addr.off, nampnt);
2059 DEBUG_Printf(DBG_CHN_TRACE,"\tAdding global data symbol %s\n", nampnt);
2060 #endif
2063 * Now we need to figure out which file this guy belongs to.
2065 DEBUG_AddSymbol( nampnt, &new_value, NULL, SYM_WIN32 );
2066 i += naux;
2067 continue;
2070 if( (coff_sym->StorageClass == IMAGE_SYM_CLASS_STATIC)
2071 && (naux == 0) )
2074 * Ignore these. They don't have anything to do with
2075 * reality.
2077 i += naux;
2078 continue;
2081 #if 0
2082 DEBUG_Printf(DBG_CHN_TRACE,"Skipping unknown entry %d %d %d\n", coff_sym->StorageClass,
2083 coff_sym->SectionNumber, naux);
2084 #endif
2087 * For now, skip past the aux entries.
2089 i += naux;
2094 * OK, we now should have a list of files, and we should have a list
2095 * of entrypoints. We need to sort the entrypoints so that we are
2096 * able to tie the line numbers with the given functions within the
2097 * file.
2099 if( coff_files != NULL )
2101 for(j=0; j < nfiles; j++)
2103 if( coff_files[j].entries != NULL )
2105 qsort(coff_files[j].entries, coff_files[j].neps,
2106 sizeof(struct name_hash *), DEBUG_cmp_sym);
2111 * Now pick apart the line number tables, and attach the entries
2112 * to the given functions.
2114 for(j=0; j < nfiles; j++)
2116 i = 0;
2117 if( coff_files[j].neps != 0 )
2118 for(k=0; k < coff_files[j].linecnt; k++)
2121 * Another monstrosity caused by the fact that we are using
2122 * a 6 byte structure, and gcc wants to pad structures to 4 byte
2123 * boundaries. Otherwise we could just index into an array.
2125 linepnt = (struct CoffLinenum *)
2126 ((unsigned int) coff_linetab +
2127 6*(coff_files[j].linetab_offset + k));
2129 * If we have spilled onto the next entrypoint, then
2130 * bump the counter..
2132 while(TRUE)
2134 if (i+1 >= coff_files[j].neps) break;
2135 DEBUG_GetSymbolAddr(coff_files[j].entries[i+1], &new_value.addr);
2136 if( (((unsigned int)module->load_addr +
2137 linepnt->VirtualAddr) >= new_value.addr.off) )
2139 i++;
2140 } else break;
2144 * Add the line number. This is always relative to the
2145 * start of the function, so we need to subtract that offset
2146 * first.
2148 DEBUG_GetSymbolAddr(coff_files[j].entries[i], &new_value.addr);
2149 DEBUG_AddLineNumber(coff_files[j].entries[i],
2150 linepnt->Linenum,
2151 (unsigned int) module->load_addr
2152 + linepnt->VirtualAddr
2153 - new_value.addr.off);
2158 rtn = TRUE;
2160 if( coff_files != NULL )
2162 for(j=0; j < nfiles; j++)
2164 if( coff_files[j].entries != NULL )
2166 DBG_free(coff_files[j].entries);
2169 DBG_free(coff_files);
2172 return (rtn);
2177 * Process a codeview line number table. Digestify the thing so that
2178 * we can easily reference the thing when we process the rest of
2179 * the information.
2181 static struct codeview_linetab_hdr *
2182 DEBUG_SnarfLinetab(char * linetab,
2183 int size)
2185 int file_segcount;
2186 char filename[PATH_MAX];
2187 unsigned int * filetab;
2188 char * fn;
2189 int i;
2190 int k;
2191 struct codeview_linetab_hdr * lt_hdr;
2192 unsigned int * lt_ptr;
2193 int nfile;
2194 int nseg;
2195 union any_size pnt;
2196 union any_size pnt2;
2197 struct startend * start;
2198 int this_seg;
2201 * Now get the important bits.
2203 pnt.c = linetab;
2204 nfile = *pnt.s++;
2205 nseg = *pnt.s++;
2207 filetab = (unsigned int *) pnt.c;
2210 * Now count up the number of segments in the file.
2212 nseg = 0;
2213 for(i=0; i<nfile; i++)
2215 pnt2.c = linetab + filetab[i];
2216 nseg += *pnt2.s;
2220 * Next allocate the header we will be returning.
2221 * There is one header for each segment, so that we can reach in
2222 * and pull bits as required.
2224 lt_hdr = (struct codeview_linetab_hdr *)
2225 DBG_alloc((nseg + 1) * sizeof(*lt_hdr));
2226 if( lt_hdr == NULL )
2228 goto leave;
2231 memset(lt_hdr, 0, sizeof(*lt_hdr) * (nseg+1));
2234 * Now fill the header we will be returning, one for each segment.
2235 * Note that this will basically just contain pointers into the existing
2236 * line table, and we do not actually copy any additional information
2237 * or allocate any additional memory.
2240 this_seg = 0;
2241 for(i=0; i<nfile; i++)
2244 * Get the pointer into the segment information.
2246 pnt2.c = linetab + filetab[i];
2247 file_segcount = *pnt2.s;
2249 pnt2.ui++;
2250 lt_ptr = (unsigned int *) pnt2.c;
2251 start = (struct startend *) (lt_ptr + file_segcount);
2254 * Now snarf the filename for all of the segments for this file.
2256 fn = (unsigned char *) (start + file_segcount);
2257 memset(filename, 0, sizeof(filename));
2258 memcpy(filename, fn + 1, *fn);
2259 fn = DBG_strdup(filename);
2261 for(k = 0; k < file_segcount; k++, this_seg++)
2263 pnt2.c = linetab + lt_ptr[k];
2264 lt_hdr[this_seg].start = start[k].start;
2265 lt_hdr[this_seg].end = start[k].end;
2266 lt_hdr[this_seg].sourcefile = fn;
2267 lt_hdr[this_seg].segno = *pnt2.s++;
2268 lt_hdr[this_seg].nline = *pnt2.s++;
2269 lt_hdr[this_seg].offtab = pnt2.ui;
2270 lt_hdr[this_seg].linetab = (unsigned short *)
2271 (pnt2.ui + lt_hdr[this_seg].nline);
2275 leave:
2277 return lt_hdr;
2281 static int
2282 DEBUG_SnarfCodeView( DBG_MODULE * module,
2283 char * cv_data,
2284 int size,
2285 struct codeview_linetab_hdr * linetab)
2287 struct name_hash * curr_func = NULL;
2288 struct wine_locals * curr_sym = NULL;
2289 int i;
2290 int j;
2291 int len;
2292 DBG_VALUE new_value;
2293 int nsect;
2294 union any_size ptr;
2295 IMAGE_SECTION_HEADER * sectp;
2296 union codeview_symbol * sym;
2297 char symname[PATH_MAX];
2298 struct name_hash * thunk_sym = NULL;
2300 ptr.c = cv_data;
2301 nsect = MSC_INFO(module)->nsect;
2302 sectp = DBG_alloc(sizeof(*sectp) * nsect);
2303 if (!sectp ||
2304 !DEBUG_READ_MEM_VERBOSE((char *)module->load_addr + MSC_INFO(module)->sect_ofs,
2305 sectp, sizeof(*sectp) * nsect))
2306 return FALSE;
2309 * Loop over the different types of records and whenever we
2310 * find something we are interested in, record it and move on.
2312 while( ptr.c - cv_data < size )
2314 sym = (union codeview_symbol *) ptr.c;
2316 if( sym->generic.len - sizeof(int) == (ptr.c - cv_data) )
2319 * This happens when we have indirect symbols that VC++ 4.2
2320 * sometimes uses when there isn't a line number table.
2321 * We ignore it - we will process and enter all of the
2322 * symbols in the global symbol table anyways, so there
2323 * isn't much point in keeping track of all of this crap.
2325 break;
2328 memset(symname, 0, sizeof(symname));
2329 switch(sym->generic.id)
2331 case S_GDATA:
2332 case S_LDATA:
2333 case S_PUB:
2335 * First, a couple of sanity checks.
2337 if( sym->data.namelen == 0 )
2339 break;
2342 if( sym->data.seg == 0 || sym->data.seg > nsect )
2344 break;
2348 * Global and local data symbols. We don't associate these
2349 * with any given source file.
2352 memcpy(symname, sym->data.name, sym->data.namelen);
2353 new_value.addr.seg = 0;
2354 new_value.type = DEBUG_GetCVType(sym->data.symtype);
2355 new_value.addr.off = (unsigned int) module->load_addr +
2356 sectp[sym->data.seg - 1].VirtualAddress +
2357 sym->data.offset;
2358 new_value.cookie = DV_TARGET;
2359 DEBUG_AddSymbol( symname, &new_value, NULL, SYM_WIN32 | SYM_DATA );
2360 break;
2361 case S_GDATA_32:
2362 case S_LDATA_32:
2363 case S_PUB_32:
2365 * First, a couple of sanity checks.
2367 if( sym->data32.namelen == 0 )
2369 break;
2372 if( sym->data32.seg == 0 || sym->data32.seg > nsect )
2374 break;
2378 * Global and local data symbols. We don't associate these
2379 * with any given source file.
2382 memcpy(symname, sym->data32.name, sym->data32.namelen);
2383 new_value.addr.seg = 0;
2384 new_value.type = DEBUG_GetCVType(sym->data32.symtype);
2385 new_value.addr.off = (unsigned int) module->load_addr +
2386 sectp[sym->data32.seg - 1].VirtualAddress +
2387 sym->data32.offset;
2388 new_value.cookie = DV_TARGET;
2389 DEBUG_AddSymbol( symname, &new_value, NULL, SYM_WIN32 | SYM_DATA );
2390 break;
2391 case S_THUNK:
2393 * Sort of like a global function, but it just points
2394 * to a thunk, which is a stupid name for what amounts to
2395 * a PLT slot in the normal jargon that everyone else uses.
2397 memcpy(symname, sym->thunk.name, sym->thunk.namelen);
2398 new_value.addr.seg = 0;
2399 new_value.type = NULL;
2400 new_value.addr.off = (unsigned int) module->load_addr +
2401 sectp[sym->thunk.segment - 1].VirtualAddress +
2402 sym->thunk.offset;
2403 new_value.cookie = DV_TARGET;
2404 thunk_sym = DEBUG_AddSymbol( symname, &new_value, NULL,
2405 SYM_WIN32 | SYM_FUNC);
2406 DEBUG_SetSymbolSize(thunk_sym, sym->thunk.thunk_len);
2407 break;
2408 case S_GPROC:
2409 case S_LPROC:
2411 * Global and static functions.
2413 memcpy(symname, sym->proc.name, sym->proc.namelen);
2414 new_value.addr.seg = 0;
2415 new_value.type = DEBUG_GetCVType(sym->proc.proctype);
2416 new_value.addr.off = (unsigned int) module->load_addr +
2417 sectp[sym->proc.segment - 1].VirtualAddress +
2418 sym->proc.offset;
2419 new_value.cookie = DV_TARGET;
2421 * See if we can find a segment that this goes with. If so,
2422 * it means that we also may have line number information
2423 * for this function.
2425 for(i=0; linetab && linetab[i].linetab != NULL; i++)
2427 if( ((unsigned int) module->load_addr
2428 + sectp[linetab[i].segno - 1].VirtualAddress
2429 + linetab[i].start <= new_value.addr.off)
2430 && ((unsigned int) module->load_addr
2431 + sectp[linetab[i].segno - 1].VirtualAddress
2432 + linetab[i].end > new_value.addr.off) )
2434 break;
2438 DEBUG_Normalize(curr_func);
2439 if( !linetab || linetab[i].linetab == NULL )
2441 curr_func = DEBUG_AddSymbol( symname, &new_value, NULL,
2442 SYM_WIN32 | SYM_FUNC);
2444 else
2447 * First, create the entry. Then dig through the linetab
2448 * and add whatever line numbers are appropriate for this
2449 * function.
2451 curr_func = DEBUG_AddSymbol( symname, &new_value,
2452 linetab[i].sourcefile,
2453 SYM_WIN32 | SYM_FUNC);
2454 for(j=0; j < linetab[i].nline; j++)
2456 if( linetab[i].offtab[j] >= sym->proc.offset
2457 && linetab[i].offtab[j] < sym->proc.offset
2458 + sym->proc.proc_len )
2460 DEBUG_AddLineNumber(curr_func, linetab[i].linetab[j],
2461 linetab[i].offtab[j] - sym->proc.offset);
2468 * Add information about where we should set breakpoints
2469 * in this function.
2471 DEBUG_SetSymbolBPOff(curr_func, sym->proc.debug_start);
2472 DEBUG_SetSymbolSize(curr_func, sym->proc.proc_len);
2473 break;
2474 case S_GPROC_32:
2475 case S_LPROC_32:
2477 * Global and static functions.
2479 memcpy(symname, sym->proc32.name, sym->proc32.namelen);
2480 new_value.addr.seg = 0;
2481 new_value.type = DEBUG_GetCVType(sym->proc32.proctype);
2482 new_value.addr.off = (unsigned int) module->load_addr +
2483 sectp[sym->proc32.segment - 1].VirtualAddress +
2484 sym->proc32.offset;
2485 new_value.cookie = DV_TARGET;
2487 * See if we can find a segment that this goes with. If so,
2488 * it means that we also may have line number information
2489 * for this function.
2491 for(i=0; linetab && linetab[i].linetab != NULL; i++)
2493 if( ((unsigned int) module->load_addr
2494 + sectp[linetab[i].segno - 1].VirtualAddress
2495 + linetab[i].start <= new_value.addr.off)
2496 && ((unsigned int) module->load_addr
2497 + sectp[linetab[i].segno - 1].VirtualAddress
2498 + linetab[i].end > new_value.addr.off) )
2500 break;
2504 DEBUG_Normalize(curr_func);
2505 if( !linetab || linetab[i].linetab == NULL )
2507 curr_func = DEBUG_AddSymbol( symname, &new_value, NULL,
2508 SYM_WIN32 | SYM_FUNC);
2510 else
2513 * First, create the entry. Then dig through the linetab
2514 * and add whatever line numbers are appropriate for this
2515 * function.
2517 curr_func = DEBUG_AddSymbol( symname, &new_value,
2518 linetab[i].sourcefile,
2519 SYM_WIN32 | SYM_FUNC);
2520 for(j=0; j < linetab[i].nline; j++)
2522 if( linetab[i].offtab[j] >= sym->proc32.offset
2523 && linetab[i].offtab[j] < sym->proc32.offset
2524 + sym->proc32.proc_len )
2526 DEBUG_AddLineNumber(curr_func, linetab[i].linetab[j],
2527 linetab[i].offtab[j] - sym->proc32.offset);
2534 * Add information about where we should set breakpoints
2535 * in this function.
2537 DEBUG_SetSymbolBPOff(curr_func, sym->proc32.debug_start);
2538 DEBUG_SetSymbolSize(curr_func, sym->proc32.proc_len);
2539 break;
2540 case S_BPREL:
2542 * Function parameters and stack variables.
2544 memcpy(symname, sym->stack.name, sym->stack.namelen);
2545 curr_sym = DEBUG_AddLocal(curr_func,
2547 sym->stack.offset,
2550 symname);
2551 DEBUG_SetLocalSymbolType(curr_sym, DEBUG_GetCVType(sym->stack.symtype));
2553 break;
2554 case S_BPREL_32:
2556 * Function parameters and stack variables.
2558 memcpy(symname, sym->stack32.name, sym->stack32.namelen);
2559 curr_sym = DEBUG_AddLocal(curr_func,
2561 sym->stack32.offset,
2564 symname);
2565 DEBUG_SetLocalSymbolType(curr_sym, DEBUG_GetCVType(sym->stack32.symtype));
2567 break;
2568 default:
2569 break;
2573 * Adjust pointer to point to next entry, rounding up to a word
2574 * boundary. MS preserving alignment? Stranger things have
2575 * happened.
2577 if( sym->generic.id == S_PROCREF
2578 || sym->generic.id == S_DATAREF
2579 || sym->generic.id == S_LPROCREF )
2581 len = (sym->generic.len + 3) & ~3;
2582 len += ptr.c[16] + 1;
2583 ptr.c += (len + 3) & ~3;
2585 else
2587 ptr.c += (sym->generic.len + 3) & ~3;
2591 if( linetab != NULL )
2593 DBG_free(linetab);
2596 DBG_free(sectp);
2597 return TRUE;
2602 * Process PDB file which contains debug information.
2605 #pragma pack(1)
2606 typedef struct _PDB_FILE
2608 DWORD size;
2609 DWORD unknown;
2611 } PDB_FILE, *PPDB_FILE;
2613 typedef struct _PDB_HEADER
2615 CHAR ident[40];
2616 DWORD signature;
2617 DWORD blocksize;
2618 WORD freelist;
2619 WORD total_alloc;
2620 PDB_FILE toc;
2621 WORD toc_block[ 1 ];
2623 } PDB_HEADER, *PPDB_HEADER;
2625 typedef struct _PDB_TOC
2627 DWORD nFiles;
2628 PDB_FILE file[ 1 ];
2630 } PDB_TOC, *PPDB_TOC;
2632 typedef struct _PDB_ROOT
2634 DWORD version;
2635 DWORD TimeDateStamp;
2636 DWORD unknown;
2637 DWORD cbNames;
2638 CHAR names[ 1 ];
2640 } PDB_ROOT, *PPDB_ROOT;
2642 typedef struct _PDB_TYPES_OLD
2644 DWORD version;
2645 WORD first_index;
2646 WORD last_index;
2647 DWORD type_size;
2648 WORD file;
2649 WORD pad;
2651 } PDB_TYPES_OLD, *PPDB_TYPES_OLD;
2653 typedef struct _PDB_TYPES
2655 DWORD version;
2656 DWORD type_offset;
2657 DWORD first_index;
2658 DWORD last_index;
2659 DWORD type_size;
2660 WORD file;
2661 WORD pad;
2662 DWORD hash_size;
2663 DWORD hash_base;
2664 DWORD hash_offset;
2665 DWORD hash_len;
2666 DWORD search_offset;
2667 DWORD search_len;
2668 DWORD unknown_offset;
2669 DWORD unknown_len;
2671 } PDB_TYPES, *PPDB_TYPES;
2673 typedef struct _PDB_SYMBOL_RANGE
2675 WORD segment;
2676 WORD pad1;
2677 DWORD offset;
2678 DWORD size;
2679 DWORD characteristics;
2680 WORD index;
2681 WORD pad2;
2683 } PDB_SYMBOL_RANGE, *PPDB_SYMBOL_RANGE;
2685 typedef struct _PDB_SYMBOL_RANGE_EX
2687 WORD segment;
2688 WORD pad1;
2689 DWORD offset;
2690 DWORD size;
2691 DWORD characteristics;
2692 WORD index;
2693 WORD pad2;
2694 DWORD timestamp;
2695 DWORD unknown;
2697 } PDB_SYMBOL_RANGE_EX, *PPDB_SYMBOL_RANGE_EX;
2699 typedef struct _PDB_SYMBOL_FILE
2701 DWORD unknown1;
2702 PDB_SYMBOL_RANGE range;
2703 WORD flag;
2704 WORD file;
2705 DWORD symbol_size;
2706 DWORD lineno_size;
2707 DWORD unknown2;
2708 DWORD nSrcFiles;
2709 DWORD attribute;
2710 CHAR filename[ 1 ];
2712 } PDB_SYMBOL_FILE, *PPDB_SYMBOL_FILE;
2714 typedef struct _PDB_SYMBOL_FILE_EX
2716 DWORD unknown1;
2717 PDB_SYMBOL_RANGE_EX range;
2718 WORD flag;
2719 WORD file;
2720 DWORD symbol_size;
2721 DWORD lineno_size;
2722 DWORD unknown2;
2723 DWORD nSrcFiles;
2724 DWORD attribute;
2725 DWORD reserved[ 2 ];
2726 CHAR filename[ 1 ];
2728 } PDB_SYMBOL_FILE_EX, *PPDB_SYMBOL_FILE_EX;
2730 typedef struct _PDB_SYMBOL_SOURCE
2732 WORD nModules;
2733 WORD nSrcFiles;
2734 WORD table[ 1 ];
2736 } PDB_SYMBOL_SOURCE, *PPDB_SYMBOL_SOURCE;
2738 typedef struct _PDB_SYMBOL_IMPORT
2740 DWORD unknown1;
2741 DWORD unknown2;
2742 DWORD TimeDateStamp;
2743 DWORD nRequests;
2744 CHAR filename[ 1 ];
2746 } PDB_SYMBOL_IMPORT, *PPDB_SYMBOL_IMPORT;
2748 typedef struct _PDB_SYMBOLS_OLD
2750 WORD hash1_file;
2751 WORD hash2_file;
2752 WORD gsym_file;
2753 WORD pad;
2754 DWORD module_size;
2755 DWORD offset_size;
2756 DWORD hash_size;
2757 DWORD srcmodule_size;
2759 } PDB_SYMBOLS_OLD, *PPDB_SYMBOLS_OLD;
2761 typedef struct _PDB_SYMBOLS
2763 DWORD signature;
2764 DWORD version;
2765 DWORD extended_format;
2766 DWORD hash1_file;
2767 DWORD hash2_file;
2768 DWORD gsym_file;
2769 DWORD module_size;
2770 DWORD offset_size;
2771 DWORD hash_size;
2772 DWORD srcmodule_size;
2773 DWORD pdbimport_size;
2774 DWORD resvd[ 5 ];
2776 } PDB_SYMBOLS, *PPDB_SYMBOLS;
2777 #pragma pack()
2780 static void *pdb_read( LPBYTE image, WORD *block_list, int size )
2782 PPDB_HEADER pdb = (PPDB_HEADER)image;
2783 int i, nBlocks;
2784 LPBYTE buffer;
2786 if ( !size ) return NULL;
2788 nBlocks = (size + pdb->blocksize-1) / pdb->blocksize;
2789 buffer = DBG_alloc( nBlocks * pdb->blocksize );
2791 for ( i = 0; i < nBlocks; i++ )
2792 memcpy( buffer + i*pdb->blocksize,
2793 image + block_list[i]*pdb->blocksize, pdb->blocksize );
2795 return buffer;
2798 static void *pdb_read_file( LPBYTE image, PPDB_TOC toc, int fileNr )
2800 PPDB_HEADER pdb = (PPDB_HEADER)image;
2801 WORD *block_list;
2802 int i;
2804 if ( !toc || fileNr >= toc->nFiles )
2805 return NULL;
2807 block_list = (WORD *) &toc->file[ toc->nFiles ];
2808 for ( i = 0; i < fileNr; i++ )
2809 block_list += (toc->file[i].size + pdb->blocksize-1) / pdb->blocksize;
2811 return pdb_read( image, block_list, toc->file[fileNr].size );
2814 static void pdb_free( void *buffer )
2816 DBG_free( buffer );
2819 static void pdb_convert_types_header( PDB_TYPES *types, char *image )
2821 memset( types, 0, sizeof(PDB_TYPES) );
2822 if ( !image ) return;
2824 if ( *(DWORD *)image < 19960000 ) /* FIXME: correct version? */
2826 /* Old version of the types record header */
2827 PDB_TYPES_OLD *old = (PDB_TYPES_OLD *)image;
2828 types->version = old->version;
2829 types->type_offset = sizeof(PDB_TYPES_OLD);
2830 types->type_size = old->type_size;
2831 types->first_index = old->first_index;
2832 types->last_index = old->last_index;
2833 types->file = old->file;
2835 else
2837 /* New version of the types record header */
2838 *types = *(PDB_TYPES *)image;
2842 static void pdb_convert_symbols_header( PDB_SYMBOLS *symbols,
2843 int *header_size, char *image )
2845 memset( symbols, 0, sizeof(PDB_SYMBOLS) );
2846 if ( !image ) return;
2848 if ( *(DWORD *)image != 0xffffffff )
2850 /* Old version of the symbols record header */
2851 PDB_SYMBOLS_OLD *old = (PDB_SYMBOLS_OLD *)image;
2852 symbols->version = 0;
2853 symbols->extended_format = 0;
2854 symbols->module_size = old->module_size;
2855 symbols->offset_size = old->offset_size;
2856 symbols->hash_size = old->hash_size;
2857 symbols->srcmodule_size = old->srcmodule_size;
2858 symbols->pdbimport_size = 0;
2859 symbols->hash1_file = old->hash1_file;
2860 symbols->hash2_file = old->hash2_file;
2861 symbols->gsym_file = old->gsym_file;
2863 *header_size = sizeof(PDB_SYMBOLS_OLD);
2865 else
2867 /* New version of the symbols record header */
2868 *symbols = *(PDB_SYMBOLS *)image;
2870 *header_size = sizeof(PDB_SYMBOLS);
2874 static int DEBUG_ProcessPDBFile( DBG_MODULE* module, const char *full_filename )
2876 HANDLE hFile, hMap;
2877 char *image = NULL;
2878 PDB_HEADER *pdb = NULL;
2879 PDB_TOC *toc = NULL;
2880 PDB_ROOT *root = NULL;
2881 char *types_image = NULL;
2882 char *symbols_image = NULL;
2883 PDB_TYPES types;
2884 PDB_SYMBOLS symbols;
2885 int header_size = 0;
2886 char *modimage, *file;
2890 * Open and map() .PDB file
2892 if ((image = DEBUG_MapDebugInfoFile(full_filename, 0, 0, &hFile, &hMap)) == NULL) {
2893 DEBUG_Printf( DBG_CHN_ERR, "-Unable to peruse .PDB file %s\n", full_filename );
2894 goto leave;
2898 * Read in TOC and well-known files
2901 pdb = (PPDB_HEADER)image;
2902 toc = pdb_read( image, pdb->toc_block, pdb->toc.size );
2903 root = pdb_read_file( image, toc, 1 );
2904 types_image = pdb_read_file( image, toc, 2 );
2905 symbols_image = pdb_read_file( image, toc, 3 );
2907 pdb_convert_types_header( &types, types_image );
2908 pdb_convert_symbols_header( &symbols, &header_size, symbols_image );
2911 * Check for unknown versions
2914 switch ( root->version )
2916 case 19950623: /* VC 4.0 */
2917 case 19950814:
2918 case 19960307: /* VC 5.0 */
2919 case 19970604: /* VC 6.0 */
2920 break;
2921 default:
2922 DEBUG_Printf( DBG_CHN_ERR, "-Unknown root block version %ld\n", root->version );
2925 switch ( types.version )
2927 case 19950410: /* VC 4.0 */
2928 case 19951122:
2929 case 19961031: /* VC 5.0 / 6.0 */
2930 break;
2931 default:
2932 DEBUG_Printf( DBG_CHN_ERR, "-Unknown type info version %ld\n", types.version );
2935 switch ( symbols.version )
2937 case 0: /* VC 4.0 */
2938 case 19960307: /* VC 5.0 */
2939 case 19970606: /* VC 6.0 */
2940 break;
2941 default:
2942 DEBUG_Printf( DBG_CHN_ERR, "-Unknown symbol info version %ld\n", symbols.version );
2947 * Check .PDB time stamp
2950 if ( root->TimeDateStamp
2951 != ((struct CodeViewDebug *)MSC_INFO(module)->dbg_info)->cv_timestamp )
2953 DEBUG_Printf(DBG_CHN_ERR, "-Wrong time stamp of .PDB file %s\n", full_filename);
2954 goto leave;
2958 * Read type table
2961 DEBUG_ParseTypeTable( types_image + types.type_offset, types.type_size );
2964 * Read type-server .PDB imports
2967 if ( symbols.pdbimport_size )
2969 /* FIXME */
2970 DEBUG_Printf(DBG_CHN_ERR, "-Type server .PDB imports ignored!\n" );
2974 * Read global symbol table
2977 modimage = pdb_read_file( image, toc, symbols.gsym_file );
2978 if ( modimage )
2980 DEBUG_SnarfCodeView( module, modimage,
2981 toc->file[symbols.gsym_file].size, NULL );
2982 pdb_free( modimage );
2986 * Read per-module symbol / linenumber tables
2989 file = symbols_image + header_size;
2990 while ( file - symbols_image < header_size + symbols.module_size )
2992 int file_nr, file_index, symbol_size, lineno_size;
2993 char *file_name;
2995 if ( !symbols.extended_format )
2997 PDB_SYMBOL_FILE *sym_file = (PDB_SYMBOL_FILE *) file;
2998 file_nr = sym_file->file;
2999 file_name = sym_file->filename;
3000 file_index = sym_file->range.index;
3001 symbol_size = sym_file->symbol_size;
3002 lineno_size = sym_file->lineno_size;
3004 else
3006 PDB_SYMBOL_FILE_EX *sym_file = (PDB_SYMBOL_FILE_EX *) file;
3007 file_nr = sym_file->file;
3008 file_name = sym_file->filename;
3009 file_index = sym_file->range.index;
3010 symbol_size = sym_file->symbol_size;
3011 lineno_size = sym_file->lineno_size;
3014 modimage = pdb_read_file( image, toc, file_nr );
3015 if ( modimage )
3017 struct codeview_linetab_hdr *linetab = NULL;
3019 if ( lineno_size )
3020 linetab = DEBUG_SnarfLinetab( modimage + symbol_size, lineno_size );
3022 if ( symbol_size )
3023 DEBUG_SnarfCodeView( module, modimage + sizeof(DWORD),
3024 symbol_size - sizeof(DWORD), linetab );
3026 pdb_free( modimage );
3029 file_name += strlen(file_name) + 1;
3030 file = (char *)( (DWORD)(file_name + strlen(file_name) + 1 + 3) & ~3 );
3034 leave:
3037 * Cleanup
3040 DEBUG_ClearTypeTable();
3042 if ( symbols_image ) pdb_free( symbols_image );
3043 if ( types_image ) pdb_free( types_image );
3044 if ( root ) pdb_free( root );
3045 if ( toc ) pdb_free( toc );
3047 DEBUG_UnmapDebugInfoFile(hFile, hMap, image);
3049 return TRUE;
3054 * Process DBG file which contains debug information.
3056 static
3058 DEBUG_ProcessDBGFile(DBG_MODULE* module, const char* filename)
3060 HANDLE hFile, hMap;
3061 char * addr;
3062 char * codeview;
3063 struct CV4_DirHead * codeview_dir;
3064 struct CV4_DirEnt * codeview_dent;
3065 PIMAGE_DEBUG_DIRECTORY dbghdr;
3066 DBG_MODULE module2;
3067 int i;
3068 int j;
3069 struct codeview_linetab_hdr * linetab;
3070 int nsect;
3071 PIMAGE_SEPARATE_DEBUG_HEADER pdbg = NULL;
3072 IMAGE_SECTION_HEADER * sectp;
3074 if ((addr = DEBUG_MapDebugInfoFile(filename, 0, 0, &hFile, &hMap)) == NULL) {
3075 DEBUG_Printf(DBG_CHN_ERR, "-Unable to peruse .DBG file %s\n", filename);
3076 goto leave;
3079 pdbg = (PIMAGE_SEPARATE_DEBUG_HEADER) addr;
3081 if( pdbg->TimeDateStamp != MSC_INFO(module)->dbgdir.TimeDateStamp )
3083 DEBUG_Printf(DBG_CHN_ERR, "Warning - %s has incorrect internal timestamp\n",
3084 filename);
3085 /* goto leave; */
3087 Well, sometimes this happens to DBG files which ARE REALLY the right .DBG
3088 files but nonetheless this check fails. Anyway, WINDBG (debugger for
3089 Windows by Microsoft) loads debug symbols which have incorrect timestamps.
3093 DEBUG_Printf(DBG_CHN_MESG, "Processing symbols from %s...\n", filename);
3095 dbghdr = (PIMAGE_DEBUG_DIRECTORY) ( addr + sizeof(*pdbg)
3096 + pdbg->NumberOfSections * sizeof(IMAGE_SECTION_HEADER)
3097 + pdbg->ExportedNamesSize);
3099 sectp = (PIMAGE_SECTION_HEADER) ((char *) pdbg + sizeof(*pdbg));
3100 nsect = pdbg->NumberOfSections;
3102 for( i=0; i < pdbg->DebugDirectorySize / sizeof(*pdbg); i++, dbghdr++ )
3104 switch(dbghdr->Type)
3106 case IMAGE_DEBUG_TYPE_COFF:
3108 * Dummy up a deferred debug header to handle the
3109 * COFF stuff embedded within the DBG file.
3111 memset((char *) &module2, 0, sizeof(module2));
3112 MSC_INFO(&module2)->dbg_info = (addr + dbghdr->PointerToRawData);
3113 MSC_INFO(&module2)->dbg_size = dbghdr->SizeOfData;
3114 module2.load_addr = module->load_addr;
3116 DEBUG_ProcessCoff(&module2);
3117 break;
3118 case IMAGE_DEBUG_TYPE_CODEVIEW:
3120 * This is the older format by which codeview stuff is
3121 * stored, known as the 'NB09' format. Newer executables
3122 * and dlls created by VC++ use PDB files instead, which
3123 * have lots of internal similarities, but the overall
3124 * format and structure is quite different.
3126 codeview = (addr + dbghdr->PointerToRawData);
3129 * The first thing in the codeview section should be
3130 * an 'NB09' identifier. As a sanity check, make sure
3131 * it is there.
3133 if( *((unsigned int*) codeview) != 0x3930424e )
3135 break;
3139 * Next we need to find the directory. This is easy too.
3141 codeview_dir = (struct CV4_DirHead *)
3142 (codeview + ((unsigned int*) codeview)[1]);
3145 * Some more sanity checks. Make sure that everything
3146 * is as we expect it.
3148 if( codeview_dir->next_offset != 0
3149 || codeview_dir->dhsize != sizeof(*codeview_dir)
3150 || codeview_dir->desize != sizeof(*codeview_dent) )
3152 break;
3154 codeview_dent = (struct CV4_DirEnt *) (codeview_dir + 1);
3156 for(j=0; j < codeview_dir->ndir; j++, codeview_dent++)
3158 if( codeview_dent->subsect_number == sstAlignSym )
3161 * Check the previous entry. If it is a
3162 * sstSrcModule, it contains the line number
3163 * info for this file.
3165 linetab = NULL;
3166 if( codeview_dent[1].module_number == codeview_dent[0].module_number
3167 && codeview_dent[1].subsect_number == sstSrcModule )
3169 linetab = DEBUG_SnarfLinetab(
3170 codeview + codeview_dent[1].offset,
3171 codeview_dent[1].size);
3174 if( codeview_dent[-1].module_number == codeview_dent[0].module_number
3175 && codeview_dent[-1].subsect_number == sstSrcModule )
3177 linetab = DEBUG_SnarfLinetab(
3178 codeview + codeview_dent[-1].offset,
3179 codeview_dent[-1].size);
3182 * Now process the CV stuff.
3184 DEBUG_SnarfCodeView(module,
3185 codeview + codeview_dent->offset + sizeof(DWORD),
3186 codeview_dent->size - sizeof(DWORD),
3187 linetab);
3191 break;
3192 default:
3193 break;
3196 leave:
3198 DEBUG_UnmapDebugInfoFile(hFile, hMap, addr);
3200 return TRUE;
3203 static int
3204 DEBUG_ProcessMSCDebugInfo(DBG_MODULE* module)
3206 struct CodeViewDebug * cvd;
3207 struct MiscDebug * misc;
3208 char * filename;
3209 int sts;
3211 switch (MSC_INFO(module)->dbgdir.Type)
3213 case IMAGE_DEBUG_TYPE_COFF:
3215 * Standard COFF debug information that VC++ adds when you
3216 * use /debugtype:both with the linker.
3218 DEBUG_Printf(DBG_CHN_TRACE, "Processing COFF symbols...\n");
3219 sts = DEBUG_ProcessCoff(module);
3220 break;
3221 case IMAGE_DEBUG_TYPE_CODEVIEW:
3223 * This is a pointer to a PDB file of some sort.
3225 cvd = (struct CodeViewDebug *) MSC_INFO(module)->dbg_info;
3227 if( strcmp(cvd->cv_nbtype, "NB10") != 0 )
3230 * Whatever this is, we don't know how to deal with
3231 * it yet.
3233 sts = FALSE;
3234 break;
3236 sts = DEBUG_ProcessPDBFile(module, cvd->cv_name);
3237 DEBUG_Printf(DBG_CHN_TRACE, "Processing PDB file %s\n", cvd->cv_name);
3238 break;
3239 case IMAGE_DEBUG_TYPE_MISC:
3241 * A pointer to a .DBG file of some sort. These files
3242 * can contain either CV4 or COFF information. Open
3243 * the file, and try to do the right thing with it.
3245 misc = (struct MiscDebug *) MSC_INFO(module)->dbg_info;
3247 filename = strrchr((char *) &misc->Data, '.');
3250 * Ignore the file if it doesn't have a .DBG extension.
3252 if( (filename == NULL)
3253 || ( (strcmp(filename, ".dbg") != 0)
3254 && (strcmp(filename, ".DBG") != 0)) )
3256 sts = FALSE;
3257 break;
3260 filename = (char *) &misc->Data;
3263 * Do the dirty deed...
3265 sts = DEBUG_ProcessDBGFile(module, filename);
3267 break;
3268 default:
3270 * We should never get here...
3272 sts = FALSE;
3273 break;
3275 module->status = (sts) ? DM_STATUS_LOADED : DM_STATUS_ERROR;
3276 return sts;