2 * File msc.c - read VC++ debug information from COFF and eventually
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.
14 * Get 16 bit CV stuff working.
15 * Add symbol size to internal symbol table.
24 #define PATH_MAX _MAX_PATH
32 IMAGE_DEBUG_DIRECTORY dbgdir;
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);
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);
63 lstrcpyn(dbg_filename, filename, MAX_PATHNAME_LEN);
68 /***********************************************************************
69 * DEBUG_MapDebugInfoFile
71 static void* DEBUG_MapDebugInfoFile(const char* name, DWORD offset, DWORD size,
72 HANDLE* hFile, HANDLE* hMap)
75 DWORD g_offset; /* offset aligned on map granuality */
76 DWORD g_size; /* size to map, with offset aligned */
82 char filename[MAX_PATHNAME_LEN];
84 DEBUG_LocateDebugInfoFile(name, filename);
85 if ((*hFile = OpenFile(filename, &ofs, OF_READ)) == HFILE_ERROR)
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)
101 if ((ret = MapViewOfFile(*hMap, FILE_MAP_READ, 0, g_offset, g_size)) != NULL)
102 ret += offset - g_offset;
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);
125 * This is a convenience structure used to map portions of the
135 * This is how we reference the various record types.
137 union codeview_symbol
151 unsigned short symtype;
152 unsigned char namelen;
153 unsigned char name[1];
160 unsigned int symtype;
163 unsigned char namelen;
164 unsigned char name[1];
171 unsigned int pparent;
175 unsigned short segment;
176 unsigned short thunk_len;
177 unsigned char thtype;
178 unsigned char namelen;
179 unsigned char name[1];
186 unsigned int pparent;
189 unsigned int proc_len;
190 unsigned int debug_start;
191 unsigned int debug_end;
193 unsigned short segment;
194 unsigned short proctype;
196 unsigned char namelen;
197 unsigned char name[1];
204 unsigned int pparent;
207 unsigned int proc_len;
208 unsigned int debug_start;
209 unsigned int debug_end;
210 unsigned int proctype;
212 unsigned short segment;
214 unsigned char namelen;
215 unsigned char name[1];
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];
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];
254 unsigned char variant[1];
261 unsigned int datatype;
262 unsigned int attribute;
263 unsigned char variant[1];
271 unsigned char bitoff;
281 unsigned char bitoff;
290 unsigned short int arrlen; /* numeric leaf */
292 unsigned char name[1];
300 unsigned int elemtype;
301 unsigned int idxtype;
302 unsigned short int arrlen; /* numeric leaf */
304 unsigned char name[1];
317 unsigned short int structlen; /* numeric leaf */
319 unsigned char name[1];
329 unsigned int fieldlist;
330 unsigned int derived;
332 unsigned short int structlen; /* numeric leaf */
334 unsigned char name[1];
345 unsigned short int un_len; /* numeric leaf */
347 unsigned char name[1];
357 unsigned int fieldlist;
358 unsigned short int un_len; /* numeric leaf */
360 unsigned char name[1];
372 unsigned char name[1];
383 unsigned char name[1];
390 unsigned char list[1];
394 union codeview_fieldtype
406 unsigned short int offset; /* numeric leaf */
414 unsigned short int offset; /* numeric leaf */
423 unsigned short int vbpoff; /* numeric leaf */
425 unsigned short int vboff; /* numeric leaf */
435 unsigned short int vbpoff; /* numeric leaf */
437 unsigned short int vboff; /* numeric leaf */
445 unsigned short int value; /* numeric leaf */
447 unsigned char name[1];
455 unsigned char name[1];
463 unsigned char name[1];
471 unsigned short int offset; /* numeric leaf */
473 unsigned char name[1];
482 unsigned short int offset; /* numeric leaf */
484 unsigned char name[1];
493 unsigned char name[1];
501 unsigned char name[1];
509 unsigned char name[1];
517 unsigned char name[1];
524 unsigned char name[1];
532 unsigned char name[1];
567 unsigned char name[1];
574 unsigned int vtab_offset;
575 unsigned char name[1];
583 unsigned char name[1];
590 unsigned int vtab_offset;
591 unsigned char name[1];
614 unsigned char name[1];
622 unsigned char name[1];
630 unsigned char name[1];
634 #define S_COMPILE 0x0001
635 #define S_REGISTER 0x0002
636 #define S_CONSTANT 0x0003
638 #define S_SSEARCH 0x0005
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
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
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.
860 unsigned int cv_timestamp;
866 unsigned int DataType;
874 * This is the header that the COFF variety of debug header points to.
878 unsigned int SymbolOffset;
879 unsigned int N_Linenum;
880 unsigned int LinenumberOffset;
881 unsigned int Unused[4];
885 unsigned int VirtualAddr;
886 unsigned short int Linenum;
890 unsigned int startaddr;
891 unsigned int endaddr;
895 struct name_hash **entries;
905 unsigned int NotLong;
906 unsigned int StrTaboff;
913 unsigned char NumberOfAuxSymbols;
916 struct CoffAuxSection{
918 unsigned short NumberOfRelocations;
919 unsigned short NumberOfLinenumbers;
920 unsigned int CheckSum;
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.
930 short unsigned int dhsize;
931 short unsigned int desize;
933 unsigned int next_offset;
938 short unsigned int subsect_number;
939 short unsigned int module_number;
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
957 unsigned short * linetab;
958 unsigned int * offtab;
964 * CodeView type information parsing
968 numeric_leaf( int *value, unsigned short int *leaf )
970 unsigned short int type = *leaf++;
973 if ( type < LF_NUMERIC )
983 *value = *(char *)leaf;
988 *value = *(short *)leaf;
993 *value = *(unsigned short *)leaf;
998 *value = *(int *)leaf;
1003 *value = *(unsigned int *)leaf;
1009 *value = 0; /* FIXME */
1014 *value = 0; /* FIXME */
1019 *value = 0; /* FIXME */
1024 *value = 0; /* FIXME */
1029 *value = 0; /* FIXME */
1034 *value = 0; /* FIXME */
1039 *value = 0; /* FIXME */
1044 *value = 0; /* FIXME */
1049 *value = 0; /* FIXME */
1054 *value = 0; /* FIXME */
1058 length += 2 + *leaf;
1059 *value = 0; /* FIXME */
1063 DEBUG_Printf( DBG_CHN_MESG, "Unknown numeric leaf type %04x\n", type );
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 )
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];
1106 if ( typeno - 0x1000 < num_cv_defined_types )
1107 dt = cv_defined_types[typeno - 0x1000];
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 )
1131 cv_defined_types[ typeno - 0x1000 ] = dt;
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;
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 );
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 );
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 );
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... */
1195 switch ( type->generic.id )
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 ),
1205 ptr += 2 + 2 + vlen + (1 + name[0]);
1210 DEBUG_Printf( DBG_CHN_MESG, "Unhandled type %04x in ENUM field list\n",
1216 return DEBUG_AddCVType( typeno, dt );
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... */
1235 switch ( type->generic.id )
1239 int offset, olen = numeric_leaf( &offset, &type->bclass.offset );
1241 /* FIXME: ignored for now */
1243 ptr += 2 + 2 + 2 + olen;
1249 int offset, olen = numeric_leaf( &offset, &type->bclass32.offset );
1251 /* FIXME: ignored for now */
1253 ptr += 2 + 2 + 4 + olen;
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;
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;
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]);
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]);
1314 /* FIXME: ignored for now */
1315 ptr += 2 + 2 + 2 + (1 + type->stmember.name[0]);
1318 case LF_STMEMBER_32:
1319 /* FIXME: ignored for now */
1320 ptr += 2 + 4 + 2 + (1 + type->stmember32.name[0]);
1324 /* FIXME: ignored for now */
1325 ptr += 2 + 2 + 2 + (1 + type->method.name[0]);
1329 /* FIXME: ignored for now */
1330 ptr += 2 + 2 + 4 + (1 + type->method32.name[0]);
1334 /* FIXME: ignored for now */
1335 ptr += 2 + 2 + (1 + type->nesttype.name[0]);
1338 case LF_NESTTYPE_32:
1339 /* FIXME: ignored for now */
1340 ptr += 2 + 2 + 4 + (1 + type->nesttype32.name[0]);
1344 /* FIXME: ignored for now */
1348 case LF_VFUNCTAB_32:
1349 /* FIXME: ignored for now */
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]);
1362 ptr += 2 + 2 + 2 + (1 + type->onemethod.name[0]);
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]);
1376 ptr += 2 + 2 + 4 + (1 + type->onemethod32.name[0]);
1382 DEBUG_Printf( DBG_CHN_MESG, "Unhandled type %04x in STRUCT field list\n",
1388 return DEBUG_AddCVType( typeno, dt );
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 );
1398 DEBUG_CopyFieldlist( dt, list );
1400 return DEBUG_AddCVType( typeno, dt );
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 );
1411 DEBUG_SetStructSize( dt, structlen );
1412 DEBUG_CopyFieldlist( dt, list );
1415 return DEBUG_AddCVType( typeno, dt );
1419 DEBUG_ParseTypeTable( char *table, int len )
1421 unsigned int curr_type = 0x1000;
1424 while ( ptr - table < len )
1426 union codeview_type *type = (union codeview_type *) ptr;
1429 switch ( type->generic.id )
1432 retv = DEBUG_AddCVType_Pointer( curr_type, type->pointer.datatype );
1435 retv = DEBUG_AddCVType_Pointer( curr_type, type->pointer32.datatype );
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 );
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 );
1458 retv = DEBUG_AddCVType_Bitfield( curr_type, type->bitfield.bitoff,
1459 type->bitfield.nbits,
1460 type->bitfield.type );
1462 case LF_BITFIELD_32:
1463 retv = DEBUG_AddCVType_Bitfield( curr_type, type->bitfield32.bitoff,
1464 type->bitfield32.nbits,
1465 type->bitfield32.type );
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 );
1491 retv = DEBUG_AddCVType_StructFieldList( curr_type, list, len );
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 );
1505 case LF_STRUCTURE_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 );
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 );
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 );
1536 retv = DEBUG_AddCVType_Enum( curr_type, terminate_string( type->enumeration.name ),
1537 type->enumeration.field );
1540 retv = DEBUG_AddCVType_Enum( curr_type, terminate_string( type->enumeration32.name ),
1541 type->enumeration32.field );
1552 ptr += type->generic.len + 2;
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;
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;
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;
1623 case IMAGE_DEBUG_TYPE_CODEVIEW:
1624 case IMAGE_DEBUG_TYPE_MISC:
1625 has_codeview = TRUE;
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;
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
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.
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
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)
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,
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);
1702 v_addr += sizeof(dbg);
1704 DEBUG_CurrProcess->next_index++;
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)))
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);
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);
1748 DEBUG_Printf(DBG_CHN_MESG, "couldn't read data block\n");
1752 DEBUG_Printf(DBG_CHN_MESG, "couldn't alloc %d bytes\n",
1753 stabsize + stabstrsize);
1760 * Process COFF debugging information embedded in a Win32 application.
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;
1772 struct CoffSymbol * coff_sym;
1773 struct CoffSymbol * coff_symbol;
1774 struct CoffFiles * curr_file = NULL;
1778 struct CoffLinenum * linepnt;
1783 DBG_VALUE new_value;
1785 int nfiles_alloc = 0;
1786 struct CoffFiles orig_file;
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);
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
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 )
1821 coff_files = (struct CoffFiles *) DBG_realloc(coff_files,
1822 nfiles_alloc * sizeof(struct CoffFiles));
1824 curr_file = coff_files + 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);
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
1844 if( (coff_sym->StorageClass == IMAGE_SYM_CLASS_STATIC)
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 )
1854 DEBUG_Printf(DBG_CHN_TRACE, "Duplicating sect from %s: %x %x %x %d %d\n",
1855 curr_file->filename,
1857 aux->NumberOfRelocations,
1858 aux->NumberOfLinenumbers,
1861 DEBUG_Printf(DBG_CHN_TRACE, "More sect %d %x %d %d %d\n",
1862 coff_sym->SectionNumber,
1865 coff_sym->StorageClass,
1866 coff_sym->NumberOfAuxSymbols);
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 )
1881 coff_files = (struct CoffFiles *) DBG_realloc(coff_files,
1882 nfiles_alloc * sizeof(struct CoffFiles));
1884 curr_file = coff_files + 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;
1897 DEBUG_Printf(DBG_CHN_TRACE, "New text sect from %s: %x %x %x %d %d\n",
1898 curr_file->filename,
1900 aux->NumberOfRelocations,
1901 aux->NumberOfLinenumbers,
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;
1929 if( (coff_sym->StorageClass == IMAGE_SYM_CLASS_STATIC)
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);
1942 nampnt = &namebuff[0];
1946 nampnt = coff_strtab + coff_sym->N.Name.StrTaboff;
1949 if( nampnt[0] == '_' )
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 *));
1965 DEBUG_Printf(DBG_CHN_TRACE,"\tAdding static symbol %s\n", nampnt);
1967 curr_file->entries[curr_file->neps++] =
1968 DEBUG_AddSymbol( nampnt, &new_value, this_file, SYM_WIN32 );
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);
1981 nampnt = &namebuff[0];
1985 nampnt = coff_strtab + coff_sym->N.Name.StrTaboff;
1989 if( nampnt[0] == '_' )
1994 new_value.addr.seg = 0;
1995 new_value.addr.off = (int) ((char *)module->load_addr + coff_sym->Value);
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);
2004 * Now we need to figure out which file this guy belongs to.
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;
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 );
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);
2040 nampnt = &namebuff[0];
2044 nampnt = coff_strtab + coff_sym->N.Name.StrTaboff;
2048 if( nampnt[0] == '_' )
2053 new_value.addr.seg = 0;
2054 new_value.addr.off = (int) ((char *)module->load_addr + coff_sym->Value);
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);
2063 * Now we need to figure out which file this guy belongs to.
2065 DEBUG_AddSymbol( nampnt, &new_value, NULL, SYM_WIN32 );
2070 if( (coff_sym->StorageClass == IMAGE_SYM_CLASS_STATIC)
2074 * Ignore these. They don't have anything to do with
2082 DEBUG_Printf(DBG_CHN_TRACE,"Skipping unknown entry %d %d %d\n", coff_sym->StorageClass,
2083 coff_sym->SectionNumber, naux);
2087 * For now, skip past the aux entries.
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
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++)
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..
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) )
2144 * Add the line number. This is always relative to the
2145 * start of the function, so we need to subtract that offset
2148 DEBUG_GetSymbolAddr(coff_files[j].entries[i], &new_value.addr);
2149 DEBUG_AddLineNumber(coff_files[j].entries[i],
2151 (unsigned int) module->load_addr
2152 + linepnt->VirtualAddr
2153 - new_value.addr.off);
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);
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
2181 static struct codeview_linetab_hdr *
2182 DEBUG_SnarfLinetab(char * linetab,
2186 char filename[PATH_MAX];
2187 unsigned int * filetab;
2191 struct codeview_linetab_hdr * lt_hdr;
2192 unsigned int * lt_ptr;
2196 union any_size pnt2;
2197 struct startend * start;
2201 * Now get the important bits.
2207 filetab = (unsigned int *) pnt.c;
2210 * Now count up the number of segments in the file.
2213 for(i=0; i<nfile; i++)
2215 pnt2.c = linetab + filetab[i];
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 )
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.
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;
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);
2282 DEBUG_SnarfCodeView( DBG_MODULE * module,
2285 struct codeview_linetab_hdr * linetab)
2287 struct name_hash * curr_func = NULL;
2288 struct wine_locals * curr_sym = NULL;
2292 DBG_VALUE new_value;
2295 IMAGE_SECTION_HEADER * sectp;
2296 union codeview_symbol * sym;
2297 char symname[PATH_MAX];
2298 struct name_hash * thunk_sym = NULL;
2301 nsect = MSC_INFO(module)->nsect;
2302 sectp = DBG_alloc(sizeof(*sectp) * nsect);
2304 !DEBUG_READ_MEM_VERBOSE((char *)module->load_addr + MSC_INFO(module)->sect_ofs,
2305 sectp, sizeof(*sectp) * nsect))
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.
2328 memset(symname, 0, sizeof(symname));
2329 switch(sym->generic.id)
2335 * First, a couple of sanity checks.
2337 if( sym->data.namelen == 0 )
2342 if( sym->data.seg == 0 || sym->data.seg > nsect )
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 +
2358 new_value.cookie = DV_TARGET;
2359 DEBUG_AddSymbol( symname, &new_value, NULL, SYM_WIN32 | SYM_DATA );
2365 * First, a couple of sanity checks.
2367 if( sym->data32.namelen == 0 )
2372 if( sym->data32.seg == 0 || sym->data32.seg > nsect )
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 +
2388 new_value.cookie = DV_TARGET;
2389 DEBUG_AddSymbol( symname, &new_value, NULL, SYM_WIN32 | SYM_DATA );
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 +
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);
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 +
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) )
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);
2447 * First, create the entry. Then dig through the linetab
2448 * and add whatever line numbers are appropriate for this
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
2471 DEBUG_SetSymbolBPOff(curr_func, sym->proc.debug_start);
2472 DEBUG_SetSymbolSize(curr_func, sym->proc.proc_len);
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 +
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) )
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);
2513 * First, create the entry. Then dig through the linetab
2514 * and add whatever line numbers are appropriate for this
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
2537 DEBUG_SetSymbolBPOff(curr_func, sym->proc32.debug_start);
2538 DEBUG_SetSymbolSize(curr_func, sym->proc32.proc_len);
2542 * Function parameters and stack variables.
2544 memcpy(symname, sym->stack.name, sym->stack.namelen);
2545 curr_sym = DEBUG_AddLocal(curr_func,
2551 DEBUG_SetLocalSymbolType(curr_sym, DEBUG_GetCVType(sym->stack.symtype));
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,
2565 DEBUG_SetLocalSymbolType(curr_sym, DEBUG_GetCVType(sym->stack32.symtype));
2573 * Adjust pointer to point to next entry, rounding up to a word
2574 * boundary. MS preserving alignment? Stranger things have
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;
2587 ptr.c += (sym->generic.len + 3) & ~3;
2591 if( linetab != NULL )
2602 * Process PDB file which contains debug information.
2606 typedef struct _PDB_FILE
2611 } PDB_FILE, *PPDB_FILE;
2613 typedef struct _PDB_HEADER
2621 WORD toc_block[ 1 ];
2623 } PDB_HEADER, *PPDB_HEADER;
2625 typedef struct _PDB_TOC
2630 } PDB_TOC, *PPDB_TOC;
2632 typedef struct _PDB_ROOT
2635 DWORD TimeDateStamp;
2640 } PDB_ROOT, *PPDB_ROOT;
2642 typedef struct _PDB_TYPES_OLD
2651 } PDB_TYPES_OLD, *PPDB_TYPES_OLD;
2653 typedef struct _PDB_TYPES
2666 DWORD search_offset;
2668 DWORD unknown_offset;
2671 } PDB_TYPES, *PPDB_TYPES;
2673 typedef struct _PDB_SYMBOL_RANGE
2679 DWORD characteristics;
2683 } PDB_SYMBOL_RANGE, *PPDB_SYMBOL_RANGE;
2685 typedef struct _PDB_SYMBOL_RANGE_EX
2691 DWORD characteristics;
2697 } PDB_SYMBOL_RANGE_EX, *PPDB_SYMBOL_RANGE_EX;
2699 typedef struct _PDB_SYMBOL_FILE
2702 PDB_SYMBOL_RANGE range;
2712 } PDB_SYMBOL_FILE, *PPDB_SYMBOL_FILE;
2714 typedef struct _PDB_SYMBOL_FILE_EX
2717 PDB_SYMBOL_RANGE_EX range;
2725 DWORD reserved[ 2 ];
2728 } PDB_SYMBOL_FILE_EX, *PPDB_SYMBOL_FILE_EX;
2730 typedef struct _PDB_SYMBOL_SOURCE
2736 } PDB_SYMBOL_SOURCE, *PPDB_SYMBOL_SOURCE;
2738 typedef struct _PDB_SYMBOL_IMPORT
2742 DWORD TimeDateStamp;
2746 } PDB_SYMBOL_IMPORT, *PPDB_SYMBOL_IMPORT;
2748 typedef struct _PDB_SYMBOLS_OLD
2757 DWORD srcmodule_size;
2759 } PDB_SYMBOLS_OLD, *PPDB_SYMBOLS_OLD;
2761 typedef struct _PDB_SYMBOLS
2765 DWORD extended_format;
2772 DWORD srcmodule_size;
2773 DWORD pdbimport_size;
2776 } PDB_SYMBOLS, *PPDB_SYMBOLS;
2780 static void *pdb_read( LPBYTE image, WORD *block_list, int size )
2782 PPDB_HEADER pdb = (PPDB_HEADER)image;
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 );
2798 static void *pdb_read_file( LPBYTE image, PPDB_TOC toc, int fileNr )
2800 PPDB_HEADER pdb = (PPDB_HEADER)image;
2804 if ( !toc || fileNr >= toc->nFiles )
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 )
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;
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);
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 )
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;
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 );
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 */
2918 case 19960307: /* VC 5.0 */
2919 case 19970604: /* VC 6.0 */
2922 DEBUG_Printf( DBG_CHN_ERR, "-Unknown root block version %ld\n", root->version );
2925 switch ( types.version )
2927 case 19950410: /* VC 4.0 */
2929 case 19961031: /* VC 5.0 / 6.0 */
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 */
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);
2961 DEBUG_ParseTypeTable( types_image + types.type_offset, types.type_size );
2964 * Read type-server .PDB imports
2967 if ( symbols.pdbimport_size )
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 );
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;
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;
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 );
3017 struct codeview_linetab_hdr *linetab = NULL;
3020 linetab = DEBUG_SnarfLinetab( modimage + symbol_size, lineno_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 );
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);
3054 * Process DBG file which contains debug information.
3058 DEBUG_ProcessDBGFile(DBG_MODULE* module, const char* filename)
3063 struct CV4_DirHead * codeview_dir;
3064 struct CV4_DirEnt * codeview_dent;
3065 PIMAGE_DEBUG_DIRECTORY dbghdr;
3069 struct codeview_linetab_hdr * linetab;
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);
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",
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);
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
3133 if( *((unsigned int*) codeview) != 0x3930424e )
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) )
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.
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),
3198 DEBUG_UnmapDebugInfoFile(hFile, hMap, addr);
3204 DEBUG_ProcessMSCDebugInfo(DBG_MODULE* module)
3206 struct CodeViewDebug * cvd;
3207 struct MiscDebug * misc;
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);
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
3236 sts = DEBUG_ProcessPDBFile(module, cvd->cv_name);
3237 DEBUG_Printf(DBG_CHN_TRACE, "Processing PDB file %s\n", cvd->cv_name);
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)) )
3260 filename = (char *) &misc->Data;
3263 * Do the dirty deed...
3265 sts = DEBUG_ProcessDBGFile(module, filename);
3270 * We should never get here...
3275 module->status = (sts) ? DM_STATUS_LOADED : DM_STATUS_ERROR;