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
31 IMAGE_DEBUG_DIRECTORY dbgdir
;
38 #define MSC_INFO(module) ((MSC_DBG_INFO*)((module)->extra_info))
40 static int DEBUG_ProcessMSCDebugInfo(DBG_MODULE
* module
);
43 * dbg_filename must be at least MAX_PATHNAME_LEN bytes in size
45 static void DEBUG_LocateDebugInfoFile(const char *filename
, char *dbg_filename
)
47 char *str1
= DBG_alloc(MAX_PATHNAME_LEN
);
48 char *str2
= DBG_alloc(MAX_PATHNAME_LEN
*10);
52 file
= strrchr(filename
, '\\');
53 if( file
== NULL
) file
= filename
; else file
++;
55 if ((GetEnvironmentVariable("_NT_SYMBOL_PATH", str1
, MAX_PATHNAME_LEN
) &&
56 (SearchPath(str1
, file
, NULL
, MAX_PATHNAME_LEN
*10, str2
, &name_part
))) ||
57 (GetEnvironmentVariable("_NT_ALT_SYMBOL_PATH", str1
, MAX_PATHNAME_LEN
) &&
58 (SearchPath(str1
, file
, NULL
, MAX_PATHNAME_LEN
*10, str2
, &name_part
))) ||
59 (SearchPath(NULL
, file
, NULL
, MAX_PATHNAME_LEN
*10, str2
, &name_part
)))
60 lstrcpyn(dbg_filename
, str2
, MAX_PATHNAME_LEN
);
62 lstrcpyn(dbg_filename
, filename
, MAX_PATHNAME_LEN
);
67 /***********************************************************************
68 * DEBUG_MapDebugInfoFile
70 static void* DEBUG_MapDebugInfoFile(const char* name
, DWORD offset
, DWORD size
,
71 HANDLE
* hFile
, HANDLE
* hMap
)
74 DWORD g_offset
; /* offset aligned on map granuality */
75 DWORD g_size
; /* size to map, with offset aligned */
81 char filename
[MAX_PATHNAME_LEN
];
83 DEBUG_LocateDebugInfoFile(name
, filename
);
84 if ((*hFile
= OpenFile(filename
, &ofs
, OF_READ
)) == HFILE_ERROR
)
89 DWORD file_size
= GetFileSize(*hFile
, NULL
);
90 if (file_size
== (DWORD
)-1) return NULL
;
91 size
= file_size
- offset
;
94 g_offset
= offset
& ~0xFFFF; /* FIXME: is granularity portable ? */
95 g_size
= offset
+ size
- g_offset
;
97 if ((*hMap
= CreateFileMapping(*hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
)) == 0)
100 if ((ret
= MapViewOfFile(*hMap
, FILE_MAP_READ
, 0, g_offset
, g_size
)) != NULL
)
101 ret
+= offset
- g_offset
;
105 /***********************************************************************
106 * DEBUG_UnmapDebugInfoFile
108 static void DEBUG_UnmapDebugInfoFile(HANDLE hFile
, HANDLE hMap
, void* addr
)
110 if (addr
) UnmapViewOfFile(addr
);
111 if (hMap
) CloseHandle(hMap
);
112 if (hFile
) CloseHandle(hFile
);
124 * This is a convenience structure used to map portions of the
134 * This is how we reference the various record types.
136 union codeview_symbol
150 unsigned short symtype
;
151 unsigned char namelen
;
152 unsigned char name
[1];
159 unsigned int symtype
;
162 unsigned char namelen
;
163 unsigned char name
[1];
170 unsigned int pparent
;
174 unsigned short segment
;
175 unsigned short thunk_len
;
176 unsigned char thtype
;
177 unsigned char namelen
;
178 unsigned char name
[1];
185 unsigned int pparent
;
188 unsigned int proc_len
;
189 unsigned int debug_start
;
190 unsigned int debug_end
;
192 unsigned short segment
;
193 unsigned short proctype
;
195 unsigned char namelen
;
196 unsigned char name
[1];
203 unsigned int pparent
;
206 unsigned int proc_len
;
207 unsigned int debug_start
;
208 unsigned int debug_end
;
209 unsigned int proctype
;
211 unsigned short segment
;
213 unsigned char namelen
;
214 unsigned char name
[1];
219 short int len
; /* Total length of this entry */
220 short int id
; /* Always S_BPREL32 */
221 unsigned int offset
; /* Stack offset relative to BP */
222 unsigned short symtype
;
223 unsigned char namelen
;
224 unsigned char name
[1];
229 short int len
; /* Total length of this entry */
230 short int id
; /* Always S_BPREL32 */
231 unsigned int offset
; /* Stack offset relative to BP */
232 unsigned int symtype
;
233 unsigned char namelen
;
234 unsigned char name
[1];
253 unsigned char variant
[1];
260 unsigned int datatype
;
261 unsigned int attribute
;
262 unsigned char variant
[1];
270 unsigned char bitoff
;
280 unsigned char bitoff
;
289 unsigned short int arrlen
; /* numeric leaf */
291 unsigned char name
[1];
299 unsigned int elemtype
;
300 unsigned int idxtype
;
301 unsigned short int arrlen
; /* numeric leaf */
303 unsigned char name
[1];
316 unsigned short int structlen
; /* numeric leaf */
318 unsigned char name
[1];
328 unsigned int fieldlist
;
329 unsigned int derived
;
331 unsigned short int structlen
; /* numeric leaf */
333 unsigned char name
[1];
344 unsigned short int un_len
; /* numeric leaf */
346 unsigned char name
[1];
356 unsigned int fieldlist
;
357 unsigned short int un_len
; /* numeric leaf */
359 unsigned char name
[1];
371 unsigned char name
[1];
382 unsigned char name
[1];
389 unsigned char list
[1];
393 union codeview_fieldtype
405 unsigned short int offset
; /* numeric leaf */
413 unsigned short int offset
; /* numeric leaf */
422 unsigned short int vbpoff
; /* numeric leaf */
424 unsigned short int vboff
; /* numeric leaf */
434 unsigned short int vbpoff
; /* numeric leaf */
436 unsigned short int vboff
; /* numeric leaf */
444 unsigned short int value
; /* numeric leaf */
446 unsigned char name
[1];
454 unsigned char name
[1];
462 unsigned char name
[1];
470 unsigned short int offset
; /* numeric leaf */
472 unsigned char name
[1];
481 unsigned short int offset
; /* numeric leaf */
483 unsigned char name
[1];
492 unsigned char name
[1];
500 unsigned char name
[1];
508 unsigned char name
[1];
516 unsigned char name
[1];
523 unsigned char name
[1];
531 unsigned char name
[1];
566 unsigned char name
[1];
573 unsigned int vtab_offset
;
574 unsigned char name
[1];
582 unsigned char name
[1];
589 unsigned int vtab_offset
;
590 unsigned char name
[1];
613 unsigned char name
[1];
621 unsigned char name
[1];
629 unsigned char name
[1];
633 #define S_COMPILE 0x0001
634 #define S_REGISTER 0x0002
635 #define S_CONSTANT 0x0003
637 #define S_SSEARCH 0x0005
639 #define S_SKIP 0x0007
640 #define S_CVRESERVE 0x0008
641 #define S_OBJNAME 0x0009
642 #define S_ENDARG 0x000a
643 #define S_COBOLUDT 0x000b
644 #define S_MANYREG 0x000c
645 #define S_RETURN 0x000d
646 #define S_ENTRYTHIS 0x000e
648 #define S_BPREL 0x0200
649 #define S_LDATA 0x0201
650 #define S_GDATA 0x0202
652 #define S_LPROC 0x0204
653 #define S_GPROC 0x0205
654 #define S_THUNK 0x0206
655 #define S_BLOCK 0x0207
656 #define S_WITH 0x0208
657 #define S_LABEL 0x0209
658 #define S_CEXMODEL 0x020a
659 #define S_VFTPATH 0x020b
660 #define S_REGREL 0x020c
661 #define S_LTHREAD 0x020d
662 #define S_GTHREAD 0x020e
664 #define S_PROCREF 0x0400
665 #define S_DATAREF 0x0401
666 #define S_ALIGN 0x0402
667 #define S_LPROCREF 0x0403
669 #define S_REGISTER_32 0x1001 /* Variants with new 32-bit type indices */
670 #define S_CONSTANT_32 0x1002
671 #define S_UDT_32 0x1003
672 #define S_COBOLUDT_32 0x1004
673 #define S_MANYREG_32 0x1005
675 #define S_BPREL_32 0x1006
676 #define S_LDATA_32 0x1007
677 #define S_GDATA_32 0x1008
678 #define S_PUB_32 0x1009
679 #define S_LPROC_32 0x100a
680 #define S_GPROC_32 0x100b
681 #define S_VFTTABLE_32 0x100c
682 #define S_REGREL_32 0x100d
683 #define S_LTHREAD_32 0x100e
684 #define S_GTHREAD_32 0x100f
688 * This covers the basic datatypes that VC++ seems to be using these days.
689 * 32 bit mode only. There are additional numbers for the pointers in 16
690 * bit mode. There are many other types listed in the documents, but these
691 * are apparently not used by the compiler, or represent pointer types
694 #define T_NOTYPE 0x0000 /* Notype */
695 #define T_ABS 0x0001 /* Abs */
696 #define T_VOID 0x0003 /* Void */
697 #define T_CHAR 0x0010 /* signed char */
698 #define T_SHORT 0x0011 /* short */
699 #define T_LONG 0x0012 /* long */
700 #define T_QUAD 0x0013 /* long long */
701 #define T_UCHAR 0x0020 /* unsigned char */
702 #define T_USHORT 0x0021 /* unsigned short */
703 #define T_ULONG 0x0022 /* unsigned long */
704 #define T_UQUAD 0x0023 /* unsigned long long */
705 #define T_REAL32 0x0040 /* float */
706 #define T_REAL64 0x0041 /* double */
707 #define T_RCHAR 0x0070 /* real char */
708 #define T_WCHAR 0x0071 /* wide char */
709 #define T_INT4 0x0074 /* int */
710 #define T_UINT4 0x0075 /* unsigned int */
712 #define T_32PVOID 0x0403 /* 32 bit near pointer to void */
713 #define T_32PCHAR 0x0410 /* 16:32 near pointer to signed char */
714 #define T_32PSHORT 0x0411 /* 16:32 near pointer to short */
715 #define T_32PLONG 0x0412 /* 16:32 near pointer to int */
716 #define T_32PQUAD 0x0413 /* 16:32 near pointer to long long */
717 #define T_32PUCHAR 0x0420 /* 16:32 near pointer to unsigned char */
718 #define T_32PUSHORT 0x0421 /* 16:32 near pointer to unsigned short */
719 #define T_32PULONG 0x0422 /* 16:32 near pointer to unsigned int */
720 #define T_32PUQUAD 0x0423 /* 16:32 near pointer to long long */
721 #define T_32PREAL32 0x0440 /* 16:32 near pointer to float */
722 #define T_32PREAL64 0x0441 /* 16:32 near pointer to float */
723 #define T_32PRCHAR 0x0470 /* 16:32 near pointer to real char */
724 #define T_32PWCHAR 0x0471 /* 16:32 near pointer to real char */
725 #define T_32PINT4 0x0474 /* 16:32 near pointer to int */
726 #define T_32PUINT4 0x0475 /* 16:32 near pointer to unsigned int */
728 #define LF_MODIFIER 0x0001
729 #define LF_POINTER 0x0002
730 #define LF_ARRAY 0x0003
731 #define LF_CLASS 0x0004
732 #define LF_STRUCTURE 0x0005
733 #define LF_UNION 0x0006
734 #define LF_ENUM 0x0007
735 #define LF_PROCEDURE 0x0008
736 #define LF_MFUNCTION 0x0009
737 #define LF_VTSHAPE 0x000a
738 #define LF_COBOL0 0x000b
739 #define LF_COBOL1 0x000c
740 #define LF_BARRAY 0x000d
741 #define LF_LABEL 0x000e
742 #define LF_NULL 0x000f
743 #define LF_NOTTRAN 0x0010
744 #define LF_DIMARRAY 0x0011
745 #define LF_VFTPATH 0x0012
746 #define LF_PRECOMP 0x0013
747 #define LF_ENDPRECOMP 0x0014
748 #define LF_OEM 0x0015
749 #define LF_TYPESERVER 0x0016
751 #define LF_MODIFIER_32 0x1001 /* variants with new 32-bit type indices */
752 #define LF_POINTER_32 0x1002
753 #define LF_ARRAY_32 0x1003
754 #define LF_CLASS_32 0x1004
755 #define LF_STRUCTURE_32 0x1005
756 #define LF_UNION_32 0x1006
757 #define LF_ENUM_32 0x1007
758 #define LF_PROCEDURE_32 0x1008
759 #define LF_MFUNCTION_32 0x1009
760 #define LF_COBOL0_32 0x100a
761 #define LF_BARRAY_32 0x100b
762 #define LF_DIMARRAY_32 0x100c
763 #define LF_VFTPATH_32 0x100d
764 #define LF_PRECOMP_32 0x100e
765 #define LF_OEM_32 0x100f
767 #define LF_SKIP 0x0200
768 #define LF_ARGLIST 0x0201
769 #define LF_DEFARG 0x0202
770 #define LF_LIST 0x0203
771 #define LF_FIELDLIST 0x0204
772 #define LF_DERIVED 0x0205
773 #define LF_BITFIELD 0x0206
774 #define LF_METHODLIST 0x0207
775 #define LF_DIMCONU 0x0208
776 #define LF_DIMCONLU 0x0209
777 #define LF_DIMVARU 0x020a
778 #define LF_DIMVARLU 0x020b
779 #define LF_REFSYM 0x020c
781 #define LF_SKIP_32 0x1200 /* variants with new 32-bit type indices */
782 #define LF_ARGLIST_32 0x1201
783 #define LF_DEFARG_32 0x1202
784 #define LF_FIELDLIST_32 0x1203
785 #define LF_DERIVED_32 0x1204
786 #define LF_BITFIELD_32 0x1205
787 #define LF_METHODLIST_32 0x1206
788 #define LF_DIMCONU_32 0x1207
789 #define LF_DIMCONLU_32 0x1208
790 #define LF_DIMVARU_32 0x1209
791 #define LF_DIMVARLU_32 0x120a
793 #define LF_BCLASS 0x0400
794 #define LF_VBCLASS 0x0401
795 #define LF_IVBCLASS 0x0402
796 #define LF_ENUMERATE 0x0403
797 #define LF_FRIENDFCN 0x0404
798 #define LF_INDEX 0x0405
799 #define LF_MEMBER 0x0406
800 #define LF_STMEMBER 0x0407
801 #define LF_METHOD 0x0408
802 #define LF_NESTTYPE 0x0409
803 #define LF_VFUNCTAB 0x040a
804 #define LF_FRIENDCLS 0x040b
805 #define LF_ONEMETHOD 0x040c
806 #define LF_VFUNCOFF 0x040d
807 #define LF_NESTTYPEEX 0x040e
808 #define LF_MEMBERMODIFY 0x040f
810 #define LF_BCLASS_32 0x1400 /* variants with new 32-bit type indices */
811 #define LF_VBCLASS_32 0x1401
812 #define LF_IVBCLASS_32 0x1402
813 #define LF_FRIENDFCN_32 0x1403
814 #define LF_INDEX_32 0x1404
815 #define LF_MEMBER_32 0x1405
816 #define LF_STMEMBER_32 0x1406
817 #define LF_METHOD_32 0x1407
818 #define LF_NESTTYPE_32 0x1408
819 #define LF_VFUNCTAB_32 0x1409
820 #define LF_FRIENDCLS_32 0x140a
821 #define LF_ONEMETHOD_32 0x140b
822 #define LF_VFUNCOFF_32 0x140c
823 #define LF_NESTTYPEEX_32 0x140d
825 #define LF_NUMERIC 0x8000 /* numeric leaf types */
826 #define LF_CHAR 0x8000
827 #define LF_SHORT 0x8001
828 #define LF_USHORT 0x8002
829 #define LF_LONG 0x8003
830 #define LF_ULONG 0x8004
831 #define LF_REAL32 0x8005
832 #define LF_REAL64 0x8006
833 #define LF_REAL80 0x8007
834 #define LF_REAL128 0x8008
835 #define LF_QUADWORD 0x8009
836 #define LF_UQUADWORD 0x800a
837 #define LF_REAL48 0x800b
838 #define LF_COMPLEX32 0x800c
839 #define LF_COMPLEX64 0x800d
840 #define LF_COMPLEX80 0x800e
841 #define LF_COMPLEX128 0x800f
842 #define LF_VARSTRING 0x8010
846 #define MAX_BUILTIN_TYPES 0x480
847 static struct datatype
* cv_basic_types
[MAX_BUILTIN_TYPES
];
848 static int num_cv_defined_types
= 0;
849 static struct datatype
**cv_defined_types
= NULL
;
852 * For the type CODEVIEW debug directory entries, the debug directory
853 * points to a structure like this. The cv_name field is the name
854 * of an external .PDB file.
859 unsigned int cv_timestamp
;
865 unsigned int DataType
;
873 * This is the header that the COFF variety of debug header points to.
877 unsigned int SymbolOffset
;
878 unsigned int N_Linenum
;
879 unsigned int LinenumberOffset
;
880 unsigned int Unused
[4];
884 unsigned int VirtualAddr
;
885 unsigned short int Linenum
;
889 unsigned int startaddr
;
890 unsigned int endaddr
;
894 struct name_hash
**entries
;
904 unsigned int NotLong
;
905 unsigned int StrTaboff
;
912 unsigned char NumberOfAuxSymbols
;
915 struct CoffAuxSection
{
917 unsigned short NumberOfRelocations
;
918 unsigned short NumberOfLinenumbers
;
919 unsigned int CheckSum
;
925 * These two structures are used in the directory within a .DBG file
926 * to locate the individual important bits that we might want to see.
929 short unsigned int dhsize
;
930 short unsigned int desize
;
932 unsigned int next_offset
;
937 short unsigned int subsect_number
;
938 short unsigned int module_number
;
944 * These are the values of interest that the subsect_number field takes.
946 #define sstAlignSym 0x125
947 #define sstSrcModule 0x127
949 struct codeview_linetab_hdr
956 unsigned short * linetab
;
957 unsigned int * offtab
;
963 * CodeView type information parsing
967 numeric_leaf( int *value
, unsigned short int *leaf
)
969 unsigned short int type
= *leaf
++;
972 if ( type
< LF_NUMERIC
)
982 *value
= *(char *)leaf
;
987 *value
= *(short *)leaf
;
992 *value
= *(unsigned short *)leaf
;
997 *value
= *(int *)leaf
;
1002 *value
= *(unsigned int *)leaf
;
1008 *value
= 0; /* FIXME */
1013 *value
= 0; /* FIXME */
1018 *value
= 0; /* FIXME */
1023 *value
= 0; /* FIXME */
1028 *value
= 0; /* FIXME */
1033 *value
= 0; /* FIXME */
1038 *value
= 0; /* FIXME */
1043 *value
= 0; /* FIXME */
1048 *value
= 0; /* FIXME */
1053 *value
= 0; /* FIXME */
1057 length
+= 2 + *leaf
;
1058 *value
= 0; /* FIXME */
1062 DEBUG_Printf( DBG_CHN_MESG
, "Unknown numeric leaf type %04x\n", type
);
1072 terminate_string( unsigned char *name
)
1074 static char symname
[256];
1076 int namelen
= name
[0];
1077 assert( namelen
>= 0 && namelen
< 256 );
1079 memcpy( symname
, name
+1, namelen
);
1080 symname
[namelen
] = '\0';
1082 if ( !*symname
|| strcmp( symname
, "__unnamed" ) == 0 )
1089 struct datatype
* DEBUG_GetCVType(unsigned int typeno
)
1091 struct datatype
* dt
= NULL
;
1094 * Convert Codeview type numbers into something we can grok internally.
1095 * Numbers < 0x1000 are all fixed builtin types. Numbers from 0x1000 and
1096 * up are all user defined (structs, etc).
1098 if ( typeno
< 0x1000 )
1100 if ( typeno
< MAX_BUILTIN_TYPES
)
1101 dt
= cv_basic_types
[typeno
];
1105 if ( typeno
- 0x1000 < num_cv_defined_types
)
1106 dt
= cv_defined_types
[typeno
- 0x1000];
1113 DEBUG_AddCVType( unsigned int typeno
, struct datatype
*dt
)
1115 while ( typeno
- 0x1000 >= num_cv_defined_types
)
1117 num_cv_defined_types
+= 0x100;
1118 cv_defined_types
= (struct datatype
**)
1119 DBG_realloc( cv_defined_types
,
1120 num_cv_defined_types
* sizeof(struct datatype
*) );
1122 memset( cv_defined_types
+ num_cv_defined_types
- 0x100,
1124 0x100 * sizeof(struct datatype
*) );
1126 if ( cv_defined_types
== NULL
)
1130 cv_defined_types
[ typeno
- 0x1000 ] = dt
;
1135 DEBUG_ClearTypeTable( void )
1137 if ( cv_defined_types
)
1138 DBG_free( cv_defined_types
);
1140 cv_defined_types
= NULL
;
1141 num_cv_defined_types
= 0;
1145 DEBUG_AddCVType_Pointer( unsigned int typeno
, unsigned int datatype
)
1147 struct datatype
*dt
=
1148 DEBUG_FindOrMakePointerType( DEBUG_GetCVType( datatype
) );
1150 return DEBUG_AddCVType( typeno
, dt
);
1154 DEBUG_AddCVType_Array( unsigned int typeno
, char *name
,
1155 unsigned int elemtype
, unsigned int arr_len
)
1157 struct datatype
*dt
= DEBUG_NewDataType( DT_ARRAY
, name
);
1158 struct datatype
*elem
= DEBUG_GetCVType( elemtype
);
1159 unsigned int elem_size
= elem
? DEBUG_GetObjectSize( elem
) : 0;
1160 unsigned int arr_max
= elem_size
? arr_len
/ elem_size
: 0;
1162 DEBUG_SetArrayParams( dt
, 0, arr_max
, elem
);
1163 return DEBUG_AddCVType( typeno
, dt
);
1167 DEBUG_AddCVType_Bitfield( unsigned int typeno
,
1168 unsigned int bitoff
, unsigned int nbits
,
1169 unsigned int basetype
)
1171 struct datatype
*dt
= DEBUG_NewDataType( DT_BITFIELD
, NULL
);
1172 struct datatype
*base
= DEBUG_GetCVType( basetype
);
1174 DEBUG_SetBitfieldParams( dt
, bitoff
, nbits
, base
);
1175 return DEBUG_AddCVType( typeno
, dt
);
1179 DEBUG_AddCVType_EnumFieldList( unsigned int typeno
, unsigned char *list
, int len
)
1181 struct datatype
*dt
= DEBUG_NewDataType( DT_ENUM
, NULL
);
1182 unsigned char *ptr
= list
;
1184 while ( ptr
- list
< len
)
1186 union codeview_fieldtype
*type
= (union codeview_fieldtype
*)ptr
;
1188 if ( *ptr
>= 0xf0 ) /* LF_PAD... */
1194 switch ( type
->generic
.id
)
1198 int value
, vlen
= numeric_leaf( &value
, &type
->enumerate
.value
);
1199 unsigned char *name
= (unsigned char *)&type
->enumerate
.value
+ vlen
;
1201 DEBUG_AddStructElement( dt
, terminate_string( name
),
1204 ptr
+= 2 + 2 + vlen
+ (1 + name
[0]);
1209 DEBUG_Printf( DBG_CHN_MESG
, "Unhandled type %04x in ENUM field list\n",
1215 return DEBUG_AddCVType( typeno
, dt
);
1219 DEBUG_AddCVType_StructFieldList( unsigned int typeno
, unsigned char *list
, int len
)
1221 struct datatype
*dt
= DEBUG_NewDataType( DT_STRUCT
, NULL
);
1222 unsigned char *ptr
= list
;
1224 while ( ptr
- list
< len
)
1226 union codeview_fieldtype
*type
= (union codeview_fieldtype
*)ptr
;
1228 if ( *ptr
>= 0xf0 ) /* LF_PAD... */
1234 switch ( type
->generic
.id
)
1238 int offset
, olen
= numeric_leaf( &offset
, &type
->bclass
.offset
);
1240 /* FIXME: ignored for now */
1242 ptr
+= 2 + 2 + 2 + olen
;
1248 int offset
, olen
= numeric_leaf( &offset
, &type
->bclass32
.offset
);
1250 /* FIXME: ignored for now */
1252 ptr
+= 2 + 2 + 4 + olen
;
1259 int vbpoff
, vbplen
= numeric_leaf( &vbpoff
, &type
->vbclass
.vbpoff
);
1260 unsigned short int *p_vboff
= (unsigned short int *)((char *)&type
->vbclass
.vbpoff
+ vbpoff
);
1261 int vpoff
, vplen
= numeric_leaf( &vpoff
, p_vboff
);
1263 /* FIXME: ignored for now */
1265 ptr
+= 2 + 2 + 2 + 2 + vbplen
+ vplen
;
1270 case LF_IVBCLASS_32
:
1272 int vbpoff
, vbplen
= numeric_leaf( &vbpoff
, &type
->vbclass32
.vbpoff
);
1273 unsigned short int *p_vboff
= (unsigned short int *)((char *)&type
->vbclass32
.vbpoff
+ vbpoff
);
1274 int vpoff
, vplen
= numeric_leaf( &vpoff
, p_vboff
);
1276 /* FIXME: ignored for now */
1278 ptr
+= 2 + 2 + 4 + 4 + vbplen
+ vplen
;
1284 int offset
, olen
= numeric_leaf( &offset
, &type
->member
.offset
);
1285 unsigned char *name
= (unsigned char *)&type
->member
.offset
+ olen
;
1287 struct datatype
*subtype
= DEBUG_GetCVType( type
->member
.type
);
1288 int elem_size
= subtype
? DEBUG_GetObjectSize( subtype
) : 0;
1290 DEBUG_AddStructElement( dt
, terminate_string( name
),
1291 subtype
, offset
<< 3, elem_size
<< 3 );
1293 ptr
+= 2 + 2 + 2 + olen
+ (1 + name
[0]);
1299 int offset
, olen
= numeric_leaf( &offset
, &type
->member32
.offset
);
1300 unsigned char *name
= (unsigned char *)&type
->member32
.offset
+ olen
;
1302 struct datatype
*subtype
= DEBUG_GetCVType( type
->member32
.type
);
1303 int elem_size
= subtype
? DEBUG_GetObjectSize( subtype
) : 0;
1305 DEBUG_AddStructElement( dt
, terminate_string( name
),
1306 subtype
, offset
<< 3, elem_size
<< 3 );
1308 ptr
+= 2 + 2 + 4 + olen
+ (1 + name
[0]);
1313 /* FIXME: ignored for now */
1314 ptr
+= 2 + 2 + 2 + (1 + type
->stmember
.name
[0]);
1317 case LF_STMEMBER_32
:
1318 /* FIXME: ignored for now */
1319 ptr
+= 2 + 4 + 2 + (1 + type
->stmember32
.name
[0]);
1323 /* FIXME: ignored for now */
1324 ptr
+= 2 + 2 + 2 + (1 + type
->method
.name
[0]);
1328 /* FIXME: ignored for now */
1329 ptr
+= 2 + 2 + 4 + (1 + type
->method32
.name
[0]);
1333 /* FIXME: ignored for now */
1334 ptr
+= 2 + 2 + (1 + type
->nesttype
.name
[0]);
1337 case LF_NESTTYPE_32
:
1338 /* FIXME: ignored for now */
1339 ptr
+= 2 + 2 + 4 + (1 + type
->nesttype32
.name
[0]);
1343 /* FIXME: ignored for now */
1347 case LF_VFUNCTAB_32
:
1348 /* FIXME: ignored for now */
1353 /* FIXME: ignored for now */
1354 switch ( (type
->onemethod
.attribute
>> 2) & 7 )
1356 case 4: case 6: /* (pure) introducing virtual method */
1357 ptr
+= 2 + 2 + 2 + 4 + (1 + type
->onemethod_virt
.name
[0]);
1361 ptr
+= 2 + 2 + 2 + (1 + type
->onemethod
.name
[0]);
1366 case LF_ONEMETHOD_32
:
1367 /* FIXME: ignored for now */
1368 switch ( (type
->onemethod32
.attribute
>> 2) & 7 )
1370 case 4: case 6: /* (pure) introducing virtual method */
1371 ptr
+= 2 + 2 + 4 + 4 + (1 + type
->onemethod32_virt
.name
[0]);
1375 ptr
+= 2 + 2 + 4 + (1 + type
->onemethod32
.name
[0]);
1381 DEBUG_Printf( DBG_CHN_MESG
, "Unhandled type %04x in STRUCT field list\n",
1387 return DEBUG_AddCVType( typeno
, dt
);
1391 DEBUG_AddCVType_Enum( unsigned int typeno
, char *name
, unsigned int fieldlist
)
1393 struct datatype
*dt
= DEBUG_NewDataType( DT_ENUM
, name
);
1394 struct datatype
*list
= DEBUG_GetCVType( fieldlist
);
1397 DEBUG_CopyFieldlist( dt
, list
);
1399 return DEBUG_AddCVType( typeno
, dt
);
1403 DEBUG_AddCVType_Struct( unsigned int typeno
, char *name
, int structlen
, unsigned int fieldlist
)
1405 struct datatype
*dt
= DEBUG_NewDataType( DT_STRUCT
, name
);
1406 struct datatype
*list
= DEBUG_GetCVType( fieldlist
);
1410 DEBUG_SetStructSize( dt
, structlen
);
1411 DEBUG_CopyFieldlist( dt
, list
);
1414 return DEBUG_AddCVType( typeno
, dt
);
1418 DEBUG_ParseTypeTable( char *table
, int len
)
1420 unsigned int curr_type
= 0x1000;
1423 while ( ptr
- table
< len
)
1425 union codeview_type
*type
= (union codeview_type
*) ptr
;
1428 switch ( type
->generic
.id
)
1431 retv
= DEBUG_AddCVType_Pointer( curr_type
, type
->pointer
.datatype
);
1434 retv
= DEBUG_AddCVType_Pointer( curr_type
, type
->pointer32
.datatype
);
1439 int arrlen
, alen
= numeric_leaf( &arrlen
, &type
->array
.arrlen
);
1440 unsigned char *name
= (unsigned char *)&type
->array
.arrlen
+ alen
;
1442 retv
= DEBUG_AddCVType_Array( curr_type
, terminate_string( name
),
1443 type
->array
.elemtype
, arrlen
);
1448 int arrlen
, alen
= numeric_leaf( &arrlen
, &type
->array32
.arrlen
);
1449 unsigned char *name
= (unsigned char *)&type
->array32
.arrlen
+ alen
;
1451 retv
= DEBUG_AddCVType_Array( curr_type
, terminate_string( name
),
1452 type
->array32
.elemtype
, type
->array32
.arrlen
);
1457 retv
= DEBUG_AddCVType_Bitfield( curr_type
, type
->bitfield
.bitoff
,
1458 type
->bitfield
.nbits
,
1459 type
->bitfield
.type
);
1461 case LF_BITFIELD_32
:
1462 retv
= DEBUG_AddCVType_Bitfield( curr_type
, type
->bitfield32
.bitoff
,
1463 type
->bitfield32
.nbits
,
1464 type
->bitfield32
.type
);
1468 case LF_FIELDLIST_32
:
1471 * A 'field list' is a CodeView-specific data type which doesn't
1472 * directly correspond to any high-level data type. It is used
1473 * to hold the collection of members of a struct, class, union
1474 * or enum type. The actual definition of that type will follow
1475 * later, and refer to the field list definition record.
1477 * As we don't have a field list type ourselves, we look ahead
1478 * in the field list to try to find out whether this field list
1479 * will be used for an enum or struct type, and create a dummy
1480 * type of the corresponding sort. Later on, the definition of
1481 * the 'real' type will copy the member / enumeration data.
1484 char *list
= type
->fieldlist
.list
;
1485 int len
= (ptr
+ type
->generic
.len
+ 2) - list
;
1487 if ( ((union codeview_fieldtype
*)list
)->generic
.id
== LF_ENUMERATE
)
1488 retv
= DEBUG_AddCVType_EnumFieldList( curr_type
, list
, len
);
1490 retv
= DEBUG_AddCVType_StructFieldList( curr_type
, list
, len
);
1497 int structlen
, slen
= numeric_leaf( &structlen
, &type
->structure
.structlen
);
1498 unsigned char *name
= (unsigned char *)&type
->structure
.structlen
+ slen
;
1500 retv
= DEBUG_AddCVType_Struct( curr_type
, terminate_string( name
),
1501 structlen
, type
->structure
.fieldlist
);
1504 case LF_STRUCTURE_32
:
1507 int structlen
, slen
= numeric_leaf( &structlen
, &type
->structure32
.structlen
);
1508 unsigned char *name
= (unsigned char *)&type
->structure32
.structlen
+ slen
;
1510 retv
= DEBUG_AddCVType_Struct( curr_type
, terminate_string( name
),
1511 structlen
, type
->structure32
.fieldlist
);
1517 int un_len
, ulen
= numeric_leaf( &un_len
, &type
->t_union
.un_len
);
1518 unsigned char *name
= (unsigned char *)&type
->t_union
.un_len
+ ulen
;
1520 retv
= DEBUG_AddCVType_Struct( curr_type
, terminate_string( name
),
1521 un_len
, type
->t_union
.fieldlist
);
1526 int un_len
, ulen
= numeric_leaf( &un_len
, &type
->t_union32
.un_len
);
1527 unsigned char *name
= (unsigned char *)&type
->t_union32
.un_len
+ ulen
;
1529 retv
= DEBUG_AddCVType_Struct( curr_type
, terminate_string( name
),
1530 un_len
, type
->t_union32
.fieldlist
);
1535 retv
= DEBUG_AddCVType_Enum( curr_type
, terminate_string( type
->enumeration
.name
),
1536 type
->enumeration
.field
);
1539 retv
= DEBUG_AddCVType_Enum( curr_type
, terminate_string( type
->enumeration32
.name
),
1540 type
->enumeration32
.field
);
1551 ptr
+= type
->generic
.len
+ 2;
1559 DEBUG_InitCVDataTypes(void)
1562 * These are the common builtin types that are used by VC++.
1564 cv_basic_types
[T_NOTYPE
] = NULL
;
1565 cv_basic_types
[T_ABS
] = NULL
;
1566 cv_basic_types
[T_VOID
] = DEBUG_NewDataType(DT_BASIC
, "void");
1567 cv_basic_types
[T_CHAR
] = DEBUG_NewDataType(DT_BASIC
, "char");
1568 cv_basic_types
[T_SHORT
] = DEBUG_NewDataType(DT_BASIC
, "short int");
1569 cv_basic_types
[T_LONG
] = DEBUG_NewDataType(DT_BASIC
, "long int");
1570 cv_basic_types
[T_QUAD
] = DEBUG_NewDataType(DT_BASIC
, "long long int");
1571 cv_basic_types
[T_UCHAR
] = DEBUG_NewDataType(DT_BASIC
, "unsigned char");
1572 cv_basic_types
[T_USHORT
] = DEBUG_NewDataType(DT_BASIC
, "short unsigned int");
1573 cv_basic_types
[T_ULONG
] = DEBUG_NewDataType(DT_BASIC
, "long unsigned int");
1574 cv_basic_types
[T_UQUAD
] = DEBUG_NewDataType(DT_BASIC
, "long long unsigned int");
1575 cv_basic_types
[T_REAL32
] = DEBUG_NewDataType(DT_BASIC
, "float");
1576 cv_basic_types
[T_REAL64
] = DEBUG_NewDataType(DT_BASIC
, "double");
1577 cv_basic_types
[T_RCHAR
] = DEBUG_NewDataType(DT_BASIC
, "char");
1578 cv_basic_types
[T_WCHAR
] = DEBUG_NewDataType(DT_BASIC
, "short");
1579 cv_basic_types
[T_INT4
] = DEBUG_NewDataType(DT_BASIC
, "int");
1580 cv_basic_types
[T_UINT4
] = DEBUG_NewDataType(DT_BASIC
, "unsigned int");
1582 cv_basic_types
[T_32PVOID
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_VOID
]);
1583 cv_basic_types
[T_32PCHAR
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_CHAR
]);
1584 cv_basic_types
[T_32PSHORT
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_SHORT
]);
1585 cv_basic_types
[T_32PLONG
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_LONG
]);
1586 cv_basic_types
[T_32PQUAD
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_QUAD
]);
1587 cv_basic_types
[T_32PUCHAR
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_UCHAR
]);
1588 cv_basic_types
[T_32PUSHORT
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_USHORT
]);
1589 cv_basic_types
[T_32PULONG
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_ULONG
]);
1590 cv_basic_types
[T_32PUQUAD
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_UQUAD
]);
1591 cv_basic_types
[T_32PREAL32
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_REAL32
]);
1592 cv_basic_types
[T_32PREAL64
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_REAL64
]);
1593 cv_basic_types
[T_32PRCHAR
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_RCHAR
]);
1594 cv_basic_types
[T_32PWCHAR
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_WCHAR
]);
1595 cv_basic_types
[T_32PINT4
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_INT4
]);
1596 cv_basic_types
[T_32PUINT4
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_UINT4
]);
1600 * In this function, we keep track of deferred debugging information
1601 * that we may need later if we were to need to use the internal debugger.
1602 * We don't fully process it here for performance reasons.
1605 DEBUG_RegisterMSCDebugInfo(DBG_MODULE
* module
, HANDLE hFile
, void* _nth
, unsigned long nth_ofs
)
1607 int has_codeview
= FALSE
;
1609 IMAGE_DEBUG_DIRECTORY dbg
;
1610 u_long v_addr
, size
, orig_size
;
1611 PIMAGE_NT_HEADERS nth
= (PIMAGE_NT_HEADERS
)_nth
;
1613 orig_size
= nth
->OptionalHeader
.DataDirectory
[IMAGE_DIRECTORY_ENTRY_DEBUG
].Size
;
1615 v_addr
= nth
->OptionalHeader
.DataDirectory
[IMAGE_DIRECTORY_ENTRY_DEBUG
].VirtualAddress
;
1616 for(size
= orig_size
; size
>= sizeof(dbg
); size
-= sizeof(dbg
))
1618 if (!DEBUG_READ_MEM_VERBOSE((void*)((char *) module
->load_addr
+ v_addr
), &dbg
, sizeof(dbg
))) continue;
1622 case IMAGE_DEBUG_TYPE_CODEVIEW
:
1623 case IMAGE_DEBUG_TYPE_MISC
:
1624 has_codeview
= TRUE
;
1627 v_addr
+= sizeof(dbg
);
1630 v_addr
= nth
->OptionalHeader
.DataDirectory
[IMAGE_DIRECTORY_ENTRY_DEBUG
].VirtualAddress
;
1631 for(size
= orig_size
; size
>= sizeof(dbg
); size
-= sizeof(dbg
))
1633 if (!DEBUG_READ_MEM_VERBOSE((void*)((char *)module
->load_addr
+ v_addr
), &dbg
, sizeof(dbg
))) continue;
1637 case IMAGE_DEBUG_TYPE_COFF
:
1639 * If we have both codeview and COFF debug info, ignore the
1640 * coff debug info as it would just confuse us, and it is
1643 * FIXME - this is broken - if we cannot find the PDB file, then
1644 * we end up with no debugging info at all. In this case, we
1645 * should use the COFF info as a backup.
1651 case IMAGE_DEBUG_TYPE_CODEVIEW
:
1652 case IMAGE_DEBUG_TYPE_MISC
:
1654 * This is usually an indirection to a .DBG file.
1655 * This is similar to (but a slightly older format) from the
1658 * First check to see if the image was 'stripped'. If so, it
1659 * means that this entry points to a .DBG file. Otherwise,
1660 * it just points to itself, and we can ignore this.
1663 if( (dbg
.Type
!= IMAGE_DEBUG_TYPE_MISC
) ||
1664 (nth
->FileHeader
.Characteristics
& IMAGE_FILE_DEBUG_STRIPPED
) != 0 )
1667 * Read the important bits. What we do after this depends
1668 * upon the type, but this is always enough so we are able
1669 * to proceed if we know what we need to do next.
1671 /* basically, the PE loader maps all sections (data, resources...), but doesn't map
1672 * the DataDirectory array's content. One its entry contains the *beloved*
1673 * debug information. (Note the DataDirectory is mapped, not its content)
1678 DEBUG_Printf(DBG_CHN_TRACE
, "PE debugging info at %ld<%ld>\n", dbg
.PointerToRawData
, dbg
.SizeOfData
);
1679 dbg_info
= DEBUG_MapDebugInfoFile(NULL
, dbg
.PointerToRawData
, dbg
.SizeOfData
,
1682 if (dbg_info
!= NULL
&&
1683 (module
->extra_info
= DBG_alloc(sizeof(MSC_DBG_INFO
))) != NULL
) {
1684 MSC_INFO(module
)->dbg_info
= dbg_info
;
1685 MSC_INFO(module
)->dbg_size
= dbg
.SizeOfData
;
1686 MSC_INFO(module
)->dbgdir
= dbg
;
1687 MSC_INFO(module
)->sect_ofs
= nth_ofs
+ OFFSET_OF(IMAGE_NT_HEADERS
, OptionalHeader
) +
1688 nth
->FileHeader
.SizeOfOptionalHeader
;
1689 MSC_INFO(module
)->nsect
= nth
->FileHeader
.NumberOfSections
;
1690 DEBUG_ProcessMSCDebugInfo(module
);
1691 DBG_free(MSC_INFO(module
));
1692 MSC_INFO(module
) = NULL
;
1694 DEBUG_UnmapDebugInfoFile(0, hMap
, dbg_info
);
1701 v_addr
+= sizeof(dbg
);
1703 DEBUG_CurrProcess
->next_index
++;
1709 /* look for stabs information in PE header (it's how mingw compiler provides its
1710 * debugging information), and also wine PE <-> ELF linking thru .wsolnk sections
1712 int DEBUG_RegisterStabsDebugInfo(DBG_MODULE
* module
, HANDLE hFile
, void* _nth
,
1713 unsigned long nth_ofs
)
1715 IMAGE_SECTION_HEADER pe_seg
;
1716 unsigned long pe_seg_ofs
;
1717 int i
, stabsize
= 0, stabstrsize
= 0;
1718 unsigned int stabs
= 0, stabstr
= 0;
1719 PIMAGE_NT_HEADERS nth
= (PIMAGE_NT_HEADERS
)_nth
;
1721 pe_seg_ofs
= nth_ofs
+ OFFSET_OF(IMAGE_NT_HEADERS
, OptionalHeader
) +
1722 nth
->FileHeader
.SizeOfOptionalHeader
;
1724 for (i
= 0; i
< nth
->FileHeader
.NumberOfSections
; i
++, pe_seg_ofs
+= sizeof(pe_seg
)) {
1725 if (!DEBUG_READ_MEM_VERBOSE((void*)((char *)module
->load_addr
+ pe_seg_ofs
),
1726 &pe_seg
, sizeof(pe_seg
)))
1729 if (!strcasecmp(pe_seg
.Name
, ".stab")) {
1730 stabs
= pe_seg
.VirtualAddress
;
1731 stabsize
= pe_seg
.SizeOfRawData
;
1732 } else if (!strncasecmp(pe_seg
.Name
, ".stabstr", 8)) {
1733 stabstr
= pe_seg
.VirtualAddress
;
1734 stabstrsize
= pe_seg
.SizeOfRawData
;
1738 if (stabstrsize
&& stabsize
) {
1739 char* s1
= DBG_alloc(stabsize
+stabstrsize
);
1742 if (DEBUG_READ_MEM_VERBOSE((char*)module
->load_addr
+ stabs
, s1
, stabsize
) &&
1743 DEBUG_READ_MEM_VERBOSE((char*)module
->load_addr
+ stabstr
,
1744 s1
+ stabsize
, stabstrsize
)) {
1745 DEBUG_ParseStabs(s1
, 0, 0, stabsize
, stabsize
, stabstrsize
);
1747 DEBUG_Printf(DBG_CHN_MESG
, "couldn't read data block\n");
1751 DEBUG_Printf(DBG_CHN_MESG
, "couldn't alloc %d bytes\n",
1752 stabsize
+ stabstrsize
);
1759 * Process COFF debugging information embedded in a Win32 application.
1764 DEBUG_ProcessCoff(DBG_MODULE
* module
)
1766 struct CoffAuxSection
* aux
;
1767 struct CoffDebug
* coff
;
1768 struct CoffFiles
* coff_files
= NULL
;
1769 struct CoffLinenum
* coff_linetab
;
1771 struct CoffSymbol
* coff_sym
;
1772 struct CoffSymbol
* coff_symbol
;
1773 struct CoffFiles
* curr_file
= NULL
;
1777 struct CoffLinenum
* linepnt
;
1782 DBG_VALUE new_value
;
1784 int nfiles_alloc
= 0;
1785 struct CoffFiles orig_file
;
1787 char * this_file
= NULL
;
1789 coff
= (struct CoffDebug
*) MSC_INFO(module
)->dbg_info
;
1791 coff_symbol
= (struct CoffSymbol
*) ((unsigned int) coff
+ coff
->SymbolOffset
);
1792 coff_linetab
= (struct CoffLinenum
*) ((unsigned int) coff
+ coff
->LinenumberOffset
);
1793 coff_strtab
= (char *) ((unsigned int) coff_symbol
+ 18*coff
->N_Sym
);
1797 new_value
.cookie
= DV_TARGET
;
1798 new_value
.type
= NULL
;
1800 for(i
=0; i
< coff
->N_Sym
; i
++ )
1803 * We do this because some compilers (i.e. gcc) incorrectly
1804 * pad the structure up to a 4 byte boundary. The structure
1805 * is really only 18 bytes long, so we have to manually make sure
1808 * FIXME - there must be a way to have autoconf figure out the
1809 * correct compiler option for this. If it is always gcc, that
1810 * makes life simpler, but I don't want to force this.
1812 coff_sym
= (struct CoffSymbol
*) ((unsigned int) coff_symbol
+ 18*i
);
1813 naux
= coff_sym
->NumberOfAuxSymbols
;
1815 if( coff_sym
->StorageClass
== IMAGE_SYM_CLASS_FILE
)
1817 if( nfiles
+ 1 >= nfiles_alloc
)
1820 coff_files
= (struct CoffFiles
*) DBG_realloc(coff_files
,
1821 nfiles_alloc
* sizeof(struct CoffFiles
));
1823 curr_file
= coff_files
+ nfiles
;
1825 curr_file
->startaddr
= 0xffffffff;
1826 curr_file
->endaddr
= 0;
1827 curr_file
->filename
= ((char *) coff_sym
) + 18;
1828 curr_file
->linetab_offset
= -1;
1829 curr_file
->linecnt
= 0;
1830 curr_file
->entries
= NULL
;
1831 curr_file
->neps
= curr_file
->neps_alloc
= 0;
1832 DEBUG_Printf(DBG_CHN_TRACE
,"New file %s\n", curr_file
->filename
);
1838 * This guy marks the size and location of the text section
1839 * for the current file. We need to keep track of this so
1840 * we can figure out what file the different global functions
1843 if( (coff_sym
->StorageClass
== IMAGE_SYM_CLASS_STATIC
)
1845 && (coff_sym
->Type
== 0)
1846 && (coff_sym
->SectionNumber
== 1) )
1848 aux
= (struct CoffAuxSection
*) ((unsigned int) coff_sym
+ 18);
1850 if( curr_file
->linetab_offset
!= -1 )
1853 DEBUG_Printf(DBG_CHN_TRACE
, "Duplicating sect from %s: %x %x %x %d %d\n",
1854 curr_file
->filename
,
1856 aux
->NumberOfRelocations
,
1857 aux
->NumberOfLinenumbers
,
1860 DEBUG_Printf(DBG_CHN_TRACE
, "More sect %d %x %d %d %d\n",
1861 coff_sym
->SectionNumber
,
1864 coff_sym
->StorageClass
,
1865 coff_sym
->NumberOfAuxSymbols
);
1869 * Save this so we can copy bits from it.
1871 orig_file
= *curr_file
;
1874 * Duplicate the file entry. We have no way to describe
1875 * multiple text sections in our current way of handling things.
1877 if( nfiles
+ 1 >= nfiles_alloc
)
1880 coff_files
= (struct CoffFiles
*) DBG_realloc(coff_files
,
1881 nfiles_alloc
* sizeof(struct CoffFiles
));
1883 curr_file
= coff_files
+ nfiles
;
1885 curr_file
->startaddr
= 0xffffffff;
1886 curr_file
->endaddr
= 0;
1887 curr_file
->filename
= orig_file
.filename
;
1888 curr_file
->linetab_offset
= -1;
1889 curr_file
->linecnt
= 0;
1890 curr_file
->entries
= NULL
;
1891 curr_file
->neps
= curr_file
->neps_alloc
= 0;
1896 DEBUG_Printf(DBG_CHN_TRACE
, "New text sect from %s: %x %x %x %d %d\n",
1897 curr_file
->filename
,
1899 aux
->NumberOfRelocations
,
1900 aux
->NumberOfLinenumbers
,
1906 if( curr_file
->startaddr
> coff_sym
->Value
)
1908 curr_file
->startaddr
= coff_sym
->Value
;
1911 if( curr_file
->startaddr
> coff_sym
->Value
)
1913 curr_file
->startaddr
= coff_sym
->Value
;
1916 if( curr_file
->endaddr
< coff_sym
->Value
+ aux
->Length
)
1918 curr_file
->endaddr
= coff_sym
->Value
+ aux
->Length
;
1921 curr_file
->linetab_offset
= linetab_indx
;
1922 curr_file
->linecnt
= aux
->NumberOfLinenumbers
;
1923 linetab_indx
+= aux
->NumberOfLinenumbers
;
1928 if( (coff_sym
->StorageClass
== IMAGE_SYM_CLASS_STATIC
)
1930 && (coff_sym
->SectionNumber
== 1) )
1933 * This is a normal static function when naux == 0.
1934 * Just register it. The current file is the correct
1935 * one in this instance.
1937 if( coff_sym
->N
.Name
.NotLong
)
1939 memcpy(namebuff
, coff_sym
->N
.ShortName
, 8);
1941 nampnt
= &namebuff
[0];
1945 nampnt
= coff_strtab
+ coff_sym
->N
.Name
.StrTaboff
;
1948 if( nampnt
[0] == '_' )
1953 new_value
.addr
.seg
= 0;
1954 new_value
.addr
.off
= (int) ((char *)module
->load_addr
+ coff_sym
->Value
);
1956 if( curr_file
->neps
+ 1 >= curr_file
->neps_alloc
)
1958 curr_file
->neps_alloc
+= 10;
1959 curr_file
->entries
= (struct name_hash
**)
1960 DBG_realloc(curr_file
->entries
,
1961 curr_file
->neps_alloc
* sizeof(struct name_hash
*));
1964 DEBUG_Printf(DBG_CHN_TRACE
,"\tAdding static symbol %s\n", nampnt
);
1966 curr_file
->entries
[curr_file
->neps
++] =
1967 DEBUG_AddSymbol( nampnt
, &new_value
, this_file
, SYM_WIN32
);
1972 if( (coff_sym
->StorageClass
== IMAGE_SYM_CLASS_EXTERNAL
)
1973 && ISFCN(coff_sym
->Type
)
1974 && (coff_sym
->SectionNumber
> 0) )
1976 if( coff_sym
->N
.Name
.NotLong
)
1978 memcpy(namebuff
, coff_sym
->N
.ShortName
, 8);
1980 nampnt
= &namebuff
[0];
1984 nampnt
= coff_strtab
+ coff_sym
->N
.Name
.StrTaboff
;
1988 if( nampnt
[0] == '_' )
1993 new_value
.addr
.seg
= 0;
1994 new_value
.addr
.off
= (int) ((char *)module
->load_addr
+ coff_sym
->Value
);
1997 DEBUG_Printf(DBG_CHN_TRACE
, "%d: %x %s\n", i
, new_value
.addr
.off
, nampnt
);
1999 DEBUG_Printf(DBG_CHN_TRACE
,"\tAdding global symbol %s\n", nampnt
);
2003 * Now we need to figure out which file this guy belongs to.
2006 for(j
=0; j
< nfiles
; j
++)
2008 if( coff_files
[j
].startaddr
<= coff_sym
->Value
2009 && coff_files
[j
].endaddr
> coff_sym
->Value
)
2011 this_file
= coff_files
[j
].filename
;
2015 if( coff_files
[j
].neps
+ 1 >= coff_files
[j
].neps_alloc
)
2017 coff_files
[j
].neps_alloc
+= 10;
2018 coff_files
[j
].entries
= (struct name_hash
**)
2019 DBG_realloc(coff_files
[j
].entries
,
2020 coff_files
[j
].neps_alloc
* sizeof(struct name_hash
*));
2022 coff_files
[j
].entries
[coff_files
[j
].neps
++] =
2023 DEBUG_AddSymbol( nampnt
, &new_value
, this_file
, SYM_WIN32
);
2028 if( (coff_sym
->StorageClass
== IMAGE_SYM_CLASS_EXTERNAL
)
2029 && (coff_sym
->SectionNumber
> 0) )
2032 * Similar to above, but for the case of data symbols.
2033 * These aren't treated as entrypoints.
2035 if( coff_sym
->N
.Name
.NotLong
)
2037 memcpy(namebuff
, coff_sym
->N
.ShortName
, 8);
2039 nampnt
= &namebuff
[0];
2043 nampnt
= coff_strtab
+ coff_sym
->N
.Name
.StrTaboff
;
2047 if( nampnt
[0] == '_' )
2052 new_value
.addr
.seg
= 0;
2053 new_value
.addr
.off
= (int) ((char *)module
->load_addr
+ coff_sym
->Value
);
2056 DEBUG_Printf(DBG_CHN_TRACE
, "%d: %x %s\n", i
, new_value
.addr
.off
, nampnt
);
2058 DEBUG_Printf(DBG_CHN_TRACE
,"\tAdding global data symbol %s\n", nampnt
);
2062 * Now we need to figure out which file this guy belongs to.
2064 DEBUG_AddSymbol( nampnt
, &new_value
, NULL
, SYM_WIN32
);
2069 if( (coff_sym
->StorageClass
== IMAGE_SYM_CLASS_STATIC
)
2073 * Ignore these. They don't have anything to do with
2081 DEBUG_Printf(DBG_CHN_TRACE
,"Skipping unknown entry %d %d %d\n", coff_sym
->StorageClass
,
2082 coff_sym
->SectionNumber
, naux
);
2086 * For now, skip past the aux entries.
2093 * OK, we now should have a list of files, and we should have a list
2094 * of entrypoints. We need to sort the entrypoints so that we are
2095 * able to tie the line numbers with the given functions within the
2098 if( coff_files
!= NULL
)
2100 for(j
=0; j
< nfiles
; j
++)
2102 if( coff_files
[j
].entries
!= NULL
)
2104 qsort(coff_files
[j
].entries
, coff_files
[j
].neps
,
2105 sizeof(struct name_hash
*), DEBUG_cmp_sym
);
2110 * Now pick apart the line number tables, and attach the entries
2111 * to the given functions.
2113 for(j
=0; j
< nfiles
; j
++)
2116 if( coff_files
[j
].neps
!= 0 )
2117 for(k
=0; k
< coff_files
[j
].linecnt
; k
++)
2120 * Another monstrosity caused by the fact that we are using
2121 * a 6 byte structure, and gcc wants to pad structures to 4 byte
2122 * boundaries. Otherwise we could just index into an array.
2124 linepnt
= (struct CoffLinenum
*)
2125 ((unsigned int) coff_linetab
+
2126 6*(coff_files
[j
].linetab_offset
+ k
));
2128 * If we have spilled onto the next entrypoint, then
2129 * bump the counter..
2133 if (i
+1 >= coff_files
[j
].neps
) break;
2134 DEBUG_GetSymbolAddr(coff_files
[j
].entries
[i
+1], &new_value
.addr
);
2135 if( (((unsigned int)module
->load_addr
+
2136 linepnt
->VirtualAddr
) >= new_value
.addr
.off
) )
2143 * Add the line number. This is always relative to the
2144 * start of the function, so we need to subtract that offset
2147 DEBUG_GetSymbolAddr(coff_files
[j
].entries
[i
], &new_value
.addr
);
2148 DEBUG_AddLineNumber(coff_files
[j
].entries
[i
],
2150 (unsigned int) module
->load_addr
2151 + linepnt
->VirtualAddr
2152 - new_value
.addr
.off
);
2159 if( coff_files
!= NULL
)
2161 for(j
=0; j
< nfiles
; j
++)
2163 if( coff_files
[j
].entries
!= NULL
)
2165 DBG_free(coff_files
[j
].entries
);
2168 DBG_free(coff_files
);
2176 * Process a codeview line number table. Digestify the thing so that
2177 * we can easily reference the thing when we process the rest of
2180 static struct codeview_linetab_hdr
*
2181 DEBUG_SnarfLinetab(char * linetab
,
2185 char filename
[PATH_MAX
];
2186 unsigned int * filetab
;
2190 struct codeview_linetab_hdr
* lt_hdr
;
2191 unsigned int * lt_ptr
;
2195 union any_size pnt2
;
2196 struct startend
* start
;
2200 * Now get the important bits.
2206 filetab
= (unsigned int *) pnt
.c
;
2209 * Now count up the number of segments in the file.
2212 for(i
=0; i
<nfile
; i
++)
2214 pnt2
.c
= linetab
+ filetab
[i
];
2219 * Next allocate the header we will be returning.
2220 * There is one header for each segment, so that we can reach in
2221 * and pull bits as required.
2223 lt_hdr
= (struct codeview_linetab_hdr
*)
2224 DBG_alloc((nseg
+ 1) * sizeof(*lt_hdr
));
2225 if( lt_hdr
== NULL
)
2230 memset(lt_hdr
, 0, sizeof(*lt_hdr
) * (nseg
+1));
2233 * Now fill the header we will be returning, one for each segment.
2234 * Note that this will basically just contain pointers into the existing
2235 * line table, and we do not actually copy any additional information
2236 * or allocate any additional memory.
2240 for(i
=0; i
<nfile
; i
++)
2243 * Get the pointer into the segment information.
2245 pnt2
.c
= linetab
+ filetab
[i
];
2246 file_segcount
= *pnt2
.s
;
2249 lt_ptr
= (unsigned int *) pnt2
.c
;
2250 start
= (struct startend
*) (lt_ptr
+ file_segcount
);
2253 * Now snarf the filename for all of the segments for this file.
2255 fn
= (unsigned char *) (start
+ file_segcount
);
2256 memset(filename
, 0, sizeof(filename
));
2257 memcpy(filename
, fn
+ 1, *fn
);
2258 fn
= DBG_strdup(filename
);
2260 for(k
= 0; k
< file_segcount
; k
++, this_seg
++)
2262 pnt2
.c
= linetab
+ lt_ptr
[k
];
2263 lt_hdr
[this_seg
].start
= start
[k
].start
;
2264 lt_hdr
[this_seg
].end
= start
[k
].end
;
2265 lt_hdr
[this_seg
].sourcefile
= fn
;
2266 lt_hdr
[this_seg
].segno
= *pnt2
.s
++;
2267 lt_hdr
[this_seg
].nline
= *pnt2
.s
++;
2268 lt_hdr
[this_seg
].offtab
= pnt2
.ui
;
2269 lt_hdr
[this_seg
].linetab
= (unsigned short *)
2270 (pnt2
.ui
+ lt_hdr
[this_seg
].nline
);
2281 DEBUG_SnarfCodeView( DBG_MODULE
* module
,
2284 struct codeview_linetab_hdr
* linetab
)
2286 struct name_hash
* curr_func
= NULL
;
2287 struct wine_locals
* curr_sym
= NULL
;
2291 DBG_VALUE new_value
;
2294 IMAGE_SECTION_HEADER
* sectp
;
2295 union codeview_symbol
* sym
;
2296 char symname
[PATH_MAX
];
2297 struct name_hash
* thunk_sym
= NULL
;
2300 nsect
= MSC_INFO(module
)->nsect
;
2301 sectp
= DBG_alloc(sizeof(*sectp
) * nsect
);
2303 !DEBUG_READ_MEM_VERBOSE((char *)module
->load_addr
+ MSC_INFO(module
)->sect_ofs
,
2304 sectp
, sizeof(*sectp
) * nsect
))
2308 * Loop over the different types of records and whenever we
2309 * find something we are interested in, record it and move on.
2311 while( ptr
.c
- cv_data
< size
)
2313 sym
= (union codeview_symbol
*) ptr
.c
;
2315 if( sym
->generic
.len
- sizeof(int) == (ptr
.c
- cv_data
) )
2318 * This happens when we have indirect symbols that VC++ 4.2
2319 * sometimes uses when there isn't a line number table.
2320 * We ignore it - we will process and enter all of the
2321 * symbols in the global symbol table anyways, so there
2322 * isn't much point in keeping track of all of this crap.
2327 memset(symname
, 0, sizeof(symname
));
2328 switch(sym
->generic
.id
)
2334 * First, a couple of sanity checks.
2336 if( sym
->data
.namelen
== 0 )
2341 if( sym
->data
.seg
== 0 || sym
->data
.seg
> nsect
)
2347 * Global and local data symbols. We don't associate these
2348 * with any given source file.
2351 memcpy(symname
, sym
->data
.name
, sym
->data
.namelen
);
2352 new_value
.addr
.seg
= 0;
2353 new_value
.type
= DEBUG_GetCVType(sym
->data
.symtype
);
2354 new_value
.addr
.off
= (unsigned int) module
->load_addr
+
2355 sectp
[sym
->data
.seg
- 1].VirtualAddress
+
2357 new_value
.cookie
= DV_TARGET
;
2358 DEBUG_AddSymbol( symname
, &new_value
, NULL
, SYM_WIN32
| SYM_DATA
);
2364 * First, a couple of sanity checks.
2366 if( sym
->data32
.namelen
== 0 )
2371 if( sym
->data32
.seg
== 0 || sym
->data32
.seg
> nsect
)
2377 * Global and local data symbols. We don't associate these
2378 * with any given source file.
2381 memcpy(symname
, sym
->data32
.name
, sym
->data32
.namelen
);
2382 new_value
.addr
.seg
= 0;
2383 new_value
.type
= DEBUG_GetCVType(sym
->data32
.symtype
);
2384 new_value
.addr
.off
= (unsigned int) module
->load_addr
+
2385 sectp
[sym
->data32
.seg
- 1].VirtualAddress
+
2387 new_value
.cookie
= DV_TARGET
;
2388 DEBUG_AddSymbol( symname
, &new_value
, NULL
, SYM_WIN32
| SYM_DATA
);
2392 * Sort of like a global function, but it just points
2393 * to a thunk, which is a stupid name for what amounts to
2394 * a PLT slot in the normal jargon that everyone else uses.
2396 memcpy(symname
, sym
->thunk
.name
, sym
->thunk
.namelen
);
2397 new_value
.addr
.seg
= 0;
2398 new_value
.type
= NULL
;
2399 new_value
.addr
.off
= (unsigned int) module
->load_addr
+
2400 sectp
[sym
->thunk
.segment
- 1].VirtualAddress
+
2402 new_value
.cookie
= DV_TARGET
;
2403 thunk_sym
= DEBUG_AddSymbol( symname
, &new_value
, NULL
,
2404 SYM_WIN32
| SYM_FUNC
);
2405 DEBUG_SetSymbolSize(thunk_sym
, sym
->thunk
.thunk_len
);
2410 * Global and static functions.
2412 memcpy(symname
, sym
->proc
.name
, sym
->proc
.namelen
);
2413 new_value
.addr
.seg
= 0;
2414 new_value
.type
= DEBUG_GetCVType(sym
->proc
.proctype
);
2415 new_value
.addr
.off
= (unsigned int) module
->load_addr
+
2416 sectp
[sym
->proc
.segment
- 1].VirtualAddress
+
2418 new_value
.cookie
= DV_TARGET
;
2420 * See if we can find a segment that this goes with. If so,
2421 * it means that we also may have line number information
2422 * for this function.
2424 for(i
=0; linetab
&& linetab
[i
].linetab
!= NULL
; i
++)
2426 if( ((unsigned int) module
->load_addr
2427 + sectp
[linetab
[i
].segno
- 1].VirtualAddress
2428 + linetab
[i
].start
<= new_value
.addr
.off
)
2429 && ((unsigned int) module
->load_addr
2430 + sectp
[linetab
[i
].segno
- 1].VirtualAddress
2431 + linetab
[i
].end
> new_value
.addr
.off
) )
2437 DEBUG_Normalize(curr_func
);
2438 if( !linetab
|| linetab
[i
].linetab
== NULL
)
2440 curr_func
= DEBUG_AddSymbol( symname
, &new_value
, NULL
,
2441 SYM_WIN32
| SYM_FUNC
);
2446 * First, create the entry. Then dig through the linetab
2447 * and add whatever line numbers are appropriate for this
2450 curr_func
= DEBUG_AddSymbol( symname
, &new_value
,
2451 linetab
[i
].sourcefile
,
2452 SYM_WIN32
| SYM_FUNC
);
2453 for(j
=0; j
< linetab
[i
].nline
; j
++)
2455 if( linetab
[i
].offtab
[j
] >= sym
->proc
.offset
2456 && linetab
[i
].offtab
[j
] < sym
->proc
.offset
2457 + sym
->proc
.proc_len
)
2459 DEBUG_AddLineNumber(curr_func
, linetab
[i
].linetab
[j
],
2460 linetab
[i
].offtab
[j
] - sym
->proc
.offset
);
2467 * Add information about where we should set breakpoints
2470 DEBUG_SetSymbolBPOff(curr_func
, sym
->proc
.debug_start
);
2471 DEBUG_SetSymbolSize(curr_func
, sym
->proc
.proc_len
);
2476 * Global and static functions.
2478 memcpy(symname
, sym
->proc32
.name
, sym
->proc32
.namelen
);
2479 new_value
.addr
.seg
= 0;
2480 new_value
.type
= DEBUG_GetCVType(sym
->proc32
.proctype
);
2481 new_value
.addr
.off
= (unsigned int) module
->load_addr
+
2482 sectp
[sym
->proc32
.segment
- 1].VirtualAddress
+
2484 new_value
.cookie
= DV_TARGET
;
2486 * See if we can find a segment that this goes with. If so,
2487 * it means that we also may have line number information
2488 * for this function.
2490 for(i
=0; linetab
&& linetab
[i
].linetab
!= NULL
; i
++)
2492 if( ((unsigned int) module
->load_addr
2493 + sectp
[linetab
[i
].segno
- 1].VirtualAddress
2494 + linetab
[i
].start
<= new_value
.addr
.off
)
2495 && ((unsigned int) module
->load_addr
2496 + sectp
[linetab
[i
].segno
- 1].VirtualAddress
2497 + linetab
[i
].end
> new_value
.addr
.off
) )
2503 DEBUG_Normalize(curr_func
);
2504 if( !linetab
|| linetab
[i
].linetab
== NULL
)
2506 curr_func
= DEBUG_AddSymbol( symname
, &new_value
, NULL
,
2507 SYM_WIN32
| SYM_FUNC
);
2512 * First, create the entry. Then dig through the linetab
2513 * and add whatever line numbers are appropriate for this
2516 curr_func
= DEBUG_AddSymbol( symname
, &new_value
,
2517 linetab
[i
].sourcefile
,
2518 SYM_WIN32
| SYM_FUNC
);
2519 for(j
=0; j
< linetab
[i
].nline
; j
++)
2521 if( linetab
[i
].offtab
[j
] >= sym
->proc32
.offset
2522 && linetab
[i
].offtab
[j
] < sym
->proc32
.offset
2523 + sym
->proc32
.proc_len
)
2525 DEBUG_AddLineNumber(curr_func
, linetab
[i
].linetab
[j
],
2526 linetab
[i
].offtab
[j
] - sym
->proc32
.offset
);
2533 * Add information about where we should set breakpoints
2536 DEBUG_SetSymbolBPOff(curr_func
, sym
->proc32
.debug_start
);
2537 DEBUG_SetSymbolSize(curr_func
, sym
->proc32
.proc_len
);
2541 * Function parameters and stack variables.
2543 memcpy(symname
, sym
->stack
.name
, sym
->stack
.namelen
);
2544 curr_sym
= DEBUG_AddLocal(curr_func
,
2550 DEBUG_SetLocalSymbolType(curr_sym
, DEBUG_GetCVType(sym
->stack
.symtype
));
2555 * Function parameters and stack variables.
2557 memcpy(symname
, sym
->stack32
.name
, sym
->stack32
.namelen
);
2558 curr_sym
= DEBUG_AddLocal(curr_func
,
2560 sym
->stack32
.offset
,
2564 DEBUG_SetLocalSymbolType(curr_sym
, DEBUG_GetCVType(sym
->stack32
.symtype
));
2572 * Adjust pointer to point to next entry, rounding up to a word
2573 * boundary. MS preserving alignment? Stranger things have
2576 if( sym
->generic
.id
== S_PROCREF
2577 || sym
->generic
.id
== S_DATAREF
2578 || sym
->generic
.id
== S_LPROCREF
)
2580 len
= (sym
->generic
.len
+ 3) & ~3;
2581 len
+= ptr
.c
[16] + 1;
2582 ptr
.c
+= (len
+ 3) & ~3;
2586 ptr
.c
+= (sym
->generic
.len
+ 3) & ~3;
2590 if( linetab
!= NULL
)
2601 * Process PDB file which contains debug information.
2605 typedef struct _PDB_FILE
2610 } PDB_FILE
, *PPDB_FILE
;
2612 typedef struct _PDB_HEADER
2620 WORD toc_block
[ 1 ];
2622 } PDB_HEADER
, *PPDB_HEADER
;
2624 typedef struct _PDB_TOC
2629 } PDB_TOC
, *PPDB_TOC
;
2631 typedef struct _PDB_ROOT
2634 DWORD TimeDateStamp
;
2639 } PDB_ROOT
, *PPDB_ROOT
;
2641 typedef struct _PDB_TYPES_OLD
2650 } PDB_TYPES_OLD
, *PPDB_TYPES_OLD
;
2652 typedef struct _PDB_TYPES
2665 DWORD search_offset
;
2667 DWORD unknown_offset
;
2670 } PDB_TYPES
, *PPDB_TYPES
;
2672 typedef struct _PDB_SYMBOL_RANGE
2678 DWORD characteristics
;
2682 } PDB_SYMBOL_RANGE
, *PPDB_SYMBOL_RANGE
;
2684 typedef struct _PDB_SYMBOL_RANGE_EX
2690 DWORD characteristics
;
2696 } PDB_SYMBOL_RANGE_EX
, *PPDB_SYMBOL_RANGE_EX
;
2698 typedef struct _PDB_SYMBOL_FILE
2701 PDB_SYMBOL_RANGE range
;
2711 } PDB_SYMBOL_FILE
, *PPDB_SYMBOL_FILE
;
2713 typedef struct _PDB_SYMBOL_FILE_EX
2716 PDB_SYMBOL_RANGE_EX range
;
2724 DWORD reserved
[ 2 ];
2727 } PDB_SYMBOL_FILE_EX
, *PPDB_SYMBOL_FILE_EX
;
2729 typedef struct _PDB_SYMBOL_SOURCE
2735 } PDB_SYMBOL_SOURCE
, *PPDB_SYMBOL_SOURCE
;
2737 typedef struct _PDB_SYMBOL_IMPORT
2741 DWORD TimeDateStamp
;
2745 } PDB_SYMBOL_IMPORT
, *PPDB_SYMBOL_IMPORT
;
2747 typedef struct _PDB_SYMBOLS_OLD
2756 DWORD srcmodule_size
;
2758 } PDB_SYMBOLS_OLD
, *PPDB_SYMBOLS_OLD
;
2760 typedef struct _PDB_SYMBOLS
2771 DWORD srcmodule_size
;
2772 DWORD pdbimport_size
;
2775 } PDB_SYMBOLS
, *PPDB_SYMBOLS
;
2779 static void *pdb_read( LPBYTE image
, WORD
*block_list
, int size
)
2781 PPDB_HEADER pdb
= (PPDB_HEADER
)image
;
2785 if ( !size
) return NULL
;
2787 nBlocks
= (size
+ pdb
->blocksize
-1) / pdb
->blocksize
;
2788 buffer
= DBG_alloc( nBlocks
* pdb
->blocksize
);
2790 for ( i
= 0; i
< nBlocks
; i
++ )
2791 memcpy( buffer
+ i
*pdb
->blocksize
,
2792 image
+ block_list
[i
]*pdb
->blocksize
, pdb
->blocksize
);
2797 static void *pdb_read_file( LPBYTE image
, PPDB_TOC toc
, int fileNr
)
2799 PPDB_HEADER pdb
= (PPDB_HEADER
)image
;
2803 if ( !toc
|| fileNr
>= toc
->nFiles
)
2806 block_list
= (WORD
*) &toc
->file
[ toc
->nFiles
];
2807 for ( i
= 0; i
< fileNr
; i
++ )
2808 block_list
+= (toc
->file
[i
].size
+ pdb
->blocksize
-1) / pdb
->blocksize
;
2810 return pdb_read( image
, block_list
, toc
->file
[fileNr
].size
);
2813 static void pdb_free( void *buffer
)
2818 static void pdb_convert_types_header( PDB_TYPES
*types
, char *image
)
2820 memset( types
, 0, sizeof(PDB_TYPES
) );
2821 if ( !image
) return;
2823 if ( *(DWORD
*)image
< 19960000 ) /* FIXME: correct version? */
2825 /* Old version of the types record header */
2826 PDB_TYPES_OLD
*old
= (PDB_TYPES_OLD
*)image
;
2827 types
->version
= old
->version
;
2828 types
->type_offset
= sizeof(PDB_TYPES_OLD
);
2829 types
->type_size
= old
->type_size
;
2830 types
->first_index
= old
->first_index
;
2831 types
->last_index
= old
->last_index
;
2832 types
->file
= old
->file
;
2836 /* New version of the types record header */
2837 *types
= *(PDB_TYPES
*)image
;
2841 static void pdb_convert_symbols_header( PDB_SYMBOLS
*symbols
,
2842 int *header_size
, char *image
)
2844 memset( symbols
, 0, sizeof(PDB_SYMBOLS
) );
2845 if ( !image
) return;
2847 if ( *(DWORD
*)image
!= 0xffffffff )
2849 /* Old version of the symbols record header */
2850 PDB_SYMBOLS_OLD
*old
= (PDB_SYMBOLS_OLD
*)image
;
2851 symbols
->version
= 0;
2852 symbols
->module_size
= old
->module_size
;
2853 symbols
->offset_size
= old
->offset_size
;
2854 symbols
->hash_size
= old
->hash_size
;
2855 symbols
->srcmodule_size
= old
->srcmodule_size
;
2856 symbols
->pdbimport_size
= 0;
2857 symbols
->hash1_file
= old
->hash1_file
;
2858 symbols
->hash2_file
= old
->hash2_file
;
2859 symbols
->gsym_file
= old
->gsym_file
;
2861 *header_size
= sizeof(PDB_SYMBOLS_OLD
);
2865 /* New version of the symbols record header */
2866 *symbols
= *(PDB_SYMBOLS
*)image
;
2868 *header_size
= sizeof(PDB_SYMBOLS
);
2872 static int DEBUG_ProcessPDBFile( DBG_MODULE
* module
, const char *full_filename
)
2876 PDB_HEADER
*pdb
= NULL
;
2877 PDB_TOC
*toc
= NULL
;
2878 PDB_ROOT
*root
= NULL
;
2879 char *types_image
= NULL
;
2880 char *symbols_image
= NULL
;
2882 PDB_SYMBOLS symbols
;
2883 int header_size
= 0;
2884 char *modimage
, *file
;
2886 DEBUG_Printf(DBG_CHN_TRACE
, "Processing PDB file %s\n", full_filename
);
2889 * Open and map() .PDB file
2891 if ((image
= DEBUG_MapDebugInfoFile(full_filename
, 0, 0, &hFile
, &hMap
)) == NULL
) {
2892 DEBUG_Printf( DBG_CHN_ERR
, "-Unable to peruse .PDB file %s\n", full_filename
);
2897 * Read in TOC and well-known files
2900 pdb
= (PPDB_HEADER
)image
;
2901 toc
= pdb_read( image
, pdb
->toc_block
, pdb
->toc
.size
);
2902 root
= pdb_read_file( image
, toc
, 1 );
2903 types_image
= pdb_read_file( image
, toc
, 2 );
2904 symbols_image
= pdb_read_file( image
, toc
, 3 );
2906 pdb_convert_types_header( &types
, types_image
);
2907 pdb_convert_symbols_header( &symbols
, &header_size
, symbols_image
);
2910 * Check for unknown versions
2913 switch ( root
->version
)
2915 case 19950623: /* VC 4.0 */
2917 case 19960307: /* VC 5.0 */
2918 case 19970604: /* VC 6.0 */
2921 DEBUG_Printf( DBG_CHN_ERR
, "-Unknown root block version %ld\n", root
->version
);
2924 switch ( types
.version
)
2926 case 19950410: /* VC 4.0 */
2928 case 19961031: /* VC 5.0 / 6.0 */
2931 DEBUG_Printf( DBG_CHN_ERR
, "-Unknown type info version %ld\n", types
.version
);
2934 switch ( symbols
.version
)
2936 case 0: /* VC 4.0 */
2937 case 19960307: /* VC 5.0 */
2938 case 19970606: /* VC 6.0 */
2941 DEBUG_Printf( DBG_CHN_ERR
, "-Unknown symbol info version %ld\n", symbols
.version
);
2946 * Check .PDB time stamp
2949 if ( root
->TimeDateStamp
2950 != ((struct CodeViewDebug
*)MSC_INFO(module
)->dbg_info
)->cv_timestamp
)
2952 /* the timestamp seems to be wrong often (we may read the file wrong)*/
2953 DEBUG_Printf(DBG_CHN_MESG
, "-Wrong time stamp of .PDB file %s (0x%08lx, 0x%08x)\n",
2954 full_filename
, root
->TimeDateStamp
,
2955 ((struct CodeViewDebug
*)MSC_INFO(module
)->dbg_info
)->cv_timestamp
);
2962 DEBUG_ParseTypeTable( types_image
+ types
.type_offset
, types
.type_size
);
2965 * Read type-server .PDB imports
2968 if ( symbols
.pdbimport_size
)
2971 DEBUG_Printf(DBG_CHN_ERR
, "-Type server .PDB imports ignored!\n" );
2975 * Read global symbol table
2978 modimage
= pdb_read_file( image
, toc
, symbols
.gsym_file
);
2981 DEBUG_SnarfCodeView( module
, modimage
,
2982 toc
->file
[symbols
.gsym_file
].size
, NULL
);
2983 pdb_free( modimage
);
2987 * Read per-module symbol / linenumber tables
2990 file
= symbols_image
+ header_size
;
2991 while ( file
- symbols_image
< header_size
+ symbols
.module_size
)
2993 int file_nr
, file_index
, symbol_size
, lineno_size
;
2996 if ( symbols
.version
< 19970000 )
2998 PDB_SYMBOL_FILE
*sym_file
= (PDB_SYMBOL_FILE
*) file
;
2999 file_nr
= sym_file
->file
;
3000 file_name
= sym_file
->filename
;
3001 file_index
= sym_file
->range
.index
;
3002 symbol_size
= sym_file
->symbol_size
;
3003 lineno_size
= sym_file
->lineno_size
;
3007 PDB_SYMBOL_FILE_EX
*sym_file
= (PDB_SYMBOL_FILE_EX
*) file
;
3008 file_nr
= sym_file
->file
;
3009 file_name
= sym_file
->filename
;
3010 file_index
= sym_file
->range
.index
;
3011 symbol_size
= sym_file
->symbol_size
;
3012 lineno_size
= sym_file
->lineno_size
;
3015 modimage
= pdb_read_file( image
, toc
, file_nr
);
3018 struct codeview_linetab_hdr
*linetab
= NULL
;
3021 linetab
= DEBUG_SnarfLinetab( modimage
+ symbol_size
, lineno_size
);
3024 DEBUG_SnarfCodeView( module
, modimage
+ sizeof(DWORD
),
3025 symbol_size
- sizeof(DWORD
), linetab
);
3027 pdb_free( modimage
);
3030 file_name
+= strlen(file_name
) + 1;
3031 file
= (char *)( (DWORD
)(file_name
+ strlen(file_name
) + 1 + 3) & ~3 );
3041 DEBUG_ClearTypeTable();
3043 if ( symbols_image
) pdb_free( symbols_image
);
3044 if ( types_image
) pdb_free( types_image
);
3045 if ( root
) pdb_free( root
);
3046 if ( toc
) pdb_free( toc
);
3048 DEBUG_UnmapDebugInfoFile(hFile
, hMap
, image
);
3055 * Process DBG file which contains debug information.
3059 DEBUG_ProcessDBGFile(DBG_MODULE
* module
, const char* filename
)
3063 PIMAGE_DEBUG_DIRECTORY dbghdr
;
3065 MSC_DBG_INFO extra_info2
;
3069 PIMAGE_SEPARATE_DEBUG_HEADER pdbg
= NULL
;
3070 IMAGE_SECTION_HEADER
* sectp
;
3072 if ((addr
= DEBUG_MapDebugInfoFile(filename
, 0, 0, &hFile
, &hMap
)) == NULL
) {
3073 DEBUG_Printf(DBG_CHN_ERR
, "-Unable to peruse .DBG file %s\n", filename
);
3077 pdbg
= (PIMAGE_SEPARATE_DEBUG_HEADER
) addr
;
3079 if( pdbg
->TimeDateStamp
!= MSC_INFO(module
)->dbgdir
.TimeDateStamp
)
3081 DEBUG_Printf(DBG_CHN_ERR
, "Warning - %s has incorrect internal timestamp\n",
3085 Well, sometimes this happens to DBG files which ARE REALLY the right .DBG
3086 files but nonetheless this check fails. Anyway, WINDBG (debugger for
3087 Windows by Microsoft) loads debug symbols which have incorrect timestamps.
3091 DEBUG_Printf(DBG_CHN_MESG
, "Processing symbols from %s...\n", filename
);
3093 dbghdr
= (PIMAGE_DEBUG_DIRECTORY
) ( addr
+ sizeof(*pdbg
)
3094 + pdbg
->NumberOfSections
* sizeof(IMAGE_SECTION_HEADER
)
3095 + pdbg
->ExportedNamesSize
);
3097 sectp
= (PIMAGE_SECTION_HEADER
) ((char *) pdbg
+ sizeof(*pdbg
));
3098 nsect
= pdbg
->NumberOfSections
;
3100 for( i
=0; i
< pdbg
->DebugDirectorySize
/ sizeof(*pdbg
); i
++, dbghdr
++ )
3102 switch(dbghdr
->Type
)
3104 case IMAGE_DEBUG_TYPE_COFF
:
3106 * Dummy up a deferred debug header to handle the
3107 * COFF stuff embedded within the DBG file.
3109 memset((char *) &module2
, 0, sizeof(module2
));
3110 module2
.extra_info
= &extra_info2
;
3111 MSC_INFO(&module2
)->dbg_info
= (addr
+ dbghdr
->PointerToRawData
);
3112 MSC_INFO(&module2
)->dbg_size
= dbghdr
->SizeOfData
;
3113 module2
.load_addr
= module
->load_addr
;
3115 DEBUG_ProcessCoff(&module2
);
3117 case IMAGE_DEBUG_TYPE_CODEVIEW
:
3120 struct CV4_DirHead
* codeview_dir
;
3121 struct CV4_DirEnt
* codeview_dent
;
3122 struct codeview_linetab_hdr
* linetab
;
3123 struct CodeViewDebug
* cvd
;
3125 cvd
= (struct CodeViewDebug
*) (addr
+ dbghdr
->PointerToRawData
);
3128 * see msdn.microsoft.com/library/specs/S66EA.HTM
3129 * for desriptions of more NBxx formats
3131 if( strcmp(cvd
->cv_nbtype
, "NB10") == 0 )
3134 * The debug information resides in a seperate pdb file.
3135 * This section contains only a filename.
3137 DEBUG_ProcessPDBFile(module
, cvd
->cv_name
);
3139 else if (strcmp(cvd
->cv_nbtype
, "NB09") == 0 )
3143 * This is the older format by which codeview stuff is
3144 * stored, known as the 'NB09' format. Newer executables
3145 * and dlls created by VC++ use PDB files instead, which
3146 * have lots of internal similarities, but the overall
3147 * format and structure is quite different.
3149 codeview
= (addr
+ dbghdr
->PointerToRawData
);
3153 * We need to find the directory. This is easy too.
3155 codeview_dir
= (struct CV4_DirHead
*)
3156 (codeview
+ ((unsigned int*) codeview
)[1]);
3159 * Some more sanity checks. Make sure that everything
3160 * is as we expect it.
3162 if( codeview_dir
->next_offset
!= 0
3163 || codeview_dir
->dhsize
!= sizeof(*codeview_dir
)
3164 || codeview_dir
->desize
!= sizeof(*codeview_dent
) )
3168 codeview_dent
= (struct CV4_DirEnt
*) (codeview_dir
+ 1);
3170 for(j
=0; j
< codeview_dir
->ndir
; j
++, codeview_dent
++)
3172 if( codeview_dent
->subsect_number
== sstAlignSym
)
3175 * Check the previous entry. If it is a
3176 * sstSrcModule, it contains the line number
3177 * info for this file.
3180 if( codeview_dent
[1].module_number
== codeview_dent
[0].module_number
3181 && codeview_dent
[1].subsect_number
== sstSrcModule
)
3183 linetab
= DEBUG_SnarfLinetab(
3184 codeview
+ codeview_dent
[1].offset
,
3185 codeview_dent
[1].size
);
3188 if( codeview_dent
[-1].module_number
== codeview_dent
[0].module_number
3189 && codeview_dent
[-1].subsect_number
== sstSrcModule
)
3191 linetab
= DEBUG_SnarfLinetab(
3192 codeview
+ codeview_dent
[-1].offset
,
3193 codeview_dent
[-1].size
);
3196 * Now process the CV stuff.
3198 DEBUG_SnarfCodeView(module
,
3199 codeview
+ codeview_dent
->offset
+ sizeof(DWORD
),
3200 codeview_dent
->size
- sizeof(DWORD
),
3207 DEBUG_Printf(DBG_CHN_ERR
, "Unknown CODEVIEW type %s in module %s\n",
3208 cvd
->cv_nbtype
, module
->module_name
);
3218 DEBUG_UnmapDebugInfoFile(hFile
, hMap
, addr
);
3224 DEBUG_ProcessMSCDebugInfo(DBG_MODULE
* module
)
3226 struct CodeViewDebug
* cvd
;
3227 struct MiscDebug
* misc
;
3231 switch (MSC_INFO(module
)->dbgdir
.Type
)
3233 case IMAGE_DEBUG_TYPE_COFF
:
3235 * Standard COFF debug information that VC++ adds when you
3236 * use /debugtype:both with the linker.
3238 DEBUG_Printf(DBG_CHN_TRACE
, "Processing COFF symbols...\n");
3239 sts
= DEBUG_ProcessCoff(module
);
3241 case IMAGE_DEBUG_TYPE_CODEVIEW
:
3243 * This is a pointer to a PDB file of some sort.
3245 cvd
= (struct CodeViewDebug
*) MSC_INFO(module
)->dbg_info
;
3247 if( strcmp(cvd
->cv_nbtype
, "NB10") != 0 )
3250 * Whatever this is, we don't know how to deal with
3254 DEBUG_Printf(DBG_CHN_ERR
, "Unknown CODEVIEW type %s in module %s\n",
3255 cvd
->cv_nbtype
, module
->module_name
);
3258 sts
= DEBUG_ProcessPDBFile(module
, cvd
->cv_name
);
3260 case IMAGE_DEBUG_TYPE_MISC
:
3262 * A pointer to a .DBG file of some sort. These files
3263 * can contain either CV4 or COFF information. Open
3264 * the file, and try to do the right thing with it.
3266 misc
= (struct MiscDebug
*) MSC_INFO(module
)->dbg_info
;
3268 filename
= strrchr((char *) &misc
->Data
, '.');
3271 * Ignore the file if it doesn't have a .DBG extension.
3273 if( (filename
== NULL
)
3274 || ( (strcmp(filename
, ".dbg") != 0)
3275 && (strcmp(filename
, ".DBG") != 0)) )
3281 filename
= (char *) &misc
->Data
;
3284 * Do the dirty deed...
3286 sts
= DEBUG_ProcessDBGFile(module
, filename
);
3291 * We should never get here...
3296 module
->status
= (sts
) ? DM_STATUS_LOADED
: DM_STATUS_ERROR
;