2 * File msc.c - read VC++ debug information from COFF and eventually
5 * Copyright (C) 1996, Eric Youngdale.
6 * Copyright (C) 1999, 2000, 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
28 #define MAX_PATHNAME_LEN 1024
37 typedef struct tagMSC_DBG_INFO
40 PIMAGE_SECTION_HEADER sectp
;
47 /*========================================================================
48 * Debug file access helper routines
52 /***********************************************************************
53 * DEBUG_LocateDebugInfoFile
55 * NOTE: dbg_filename must be at least MAX_PATHNAME_LEN bytes in size
57 static void DEBUG_LocateDebugInfoFile(const char *filename
, char *dbg_filename
)
59 char *str1
= DBG_alloc(MAX_PATHNAME_LEN
);
60 char *str2
= DBG_alloc(MAX_PATHNAME_LEN
*10);
64 file
= strrchr(filename
, '\\');
65 if( file
== NULL
) file
= filename
; else file
++;
67 if ((GetEnvironmentVariable("_NT_SYMBOL_PATH", str1
, MAX_PATHNAME_LEN
) &&
68 (SearchPath(str1
, file
, NULL
, MAX_PATHNAME_LEN
*10, str2
, &name_part
))) ||
69 (GetEnvironmentVariable("_NT_ALT_SYMBOL_PATH", str1
, MAX_PATHNAME_LEN
) &&
70 (SearchPath(str1
, file
, NULL
, MAX_PATHNAME_LEN
*10, str2
, &name_part
))) ||
71 (SearchPath(NULL
, file
, NULL
, MAX_PATHNAME_LEN
*10, str2
, &name_part
)))
72 lstrcpyn(dbg_filename
, str2
, MAX_PATHNAME_LEN
);
74 lstrcpyn(dbg_filename
, filename
, MAX_PATHNAME_LEN
);
79 /***********************************************************************
80 * DEBUG_MapDebugInfoFile
82 static void* DEBUG_MapDebugInfoFile(const char* name
, DWORD offset
, DWORD size
,
83 HANDLE
* hFile
, HANDLE
* hMap
)
85 DWORD g_offset
; /* offset aligned on map granuality */
86 DWORD g_size
; /* size to map, with offset aligned */
92 char filename
[MAX_PATHNAME_LEN
];
94 DEBUG_LocateDebugInfoFile(name
, filename
);
95 if ((*hFile
= CreateFile(filename
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
)) == INVALID_HANDLE_VALUE
)
100 DWORD file_size
= GetFileSize(*hFile
, NULL
);
101 if (file_size
== (DWORD
)-1) return NULL
;
102 size
= file_size
- offset
;
105 g_offset
= offset
& ~0xFFFF; /* FIXME: is granularity portable ? */
106 g_size
= offset
+ size
- g_offset
;
108 if ((*hMap
= CreateFileMapping(*hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
)) == 0)
111 if ((ret
= MapViewOfFile(*hMap
, FILE_MAP_READ
, 0, g_offset
, g_size
)) != NULL
)
112 ret
+= offset
- g_offset
;
116 /***********************************************************************
117 * DEBUG_UnmapDebugInfoFile
119 static void DEBUG_UnmapDebugInfoFile(HANDLE hFile
, HANDLE hMap
, void* addr
)
121 if (addr
) UnmapViewOfFile(addr
);
122 if (hMap
) CloseHandle(hMap
);
123 if (hFile
!=INVALID_HANDLE_VALUE
) CloseHandle(hFile
);
128 /*========================================================================
129 * Process COFF debug information.
134 unsigned int startaddr
;
135 unsigned int endaddr
;
136 const char *filename
;
139 struct name_hash
**entries
;
146 struct CoffFile
*files
;
151 static const char* DEBUG_GetCoffName( PIMAGE_SYMBOL coff_sym
, const char* coff_strtab
)
153 static char namebuff
[9];
156 if( coff_sym
->N
.Name
.Short
)
158 memcpy(namebuff
, coff_sym
->N
.ShortName
, 8);
160 nampnt
= &namebuff
[0];
164 nampnt
= coff_strtab
+ coff_sym
->N
.Name
.Long
;
167 if( nampnt
[0] == '_' )
172 static int DEBUG_AddCoffFile( struct CoffFileSet
* coff_files
, const char* filename
)
174 struct CoffFile
* file
;
176 if( coff_files
->nfiles
+ 1 >= coff_files
->nfiles_alloc
)
178 coff_files
->nfiles_alloc
+= 10;
179 coff_files
->files
= (struct CoffFile
*) DBG_realloc(coff_files
->files
,
180 coff_files
->nfiles_alloc
* sizeof(struct CoffFile
));
182 file
= coff_files
->files
+ coff_files
->nfiles
;
183 file
->startaddr
= 0xffffffff;
185 file
->filename
= filename
;
186 file
->linetab_offset
= -1;
188 file
->entries
= NULL
;
189 file
->neps
= file
->neps_alloc
= 0;
191 return coff_files
->nfiles
++;
194 static void DEBUG_AddCoffSymbol( struct CoffFile
* coff_file
, struct name_hash
* sym
)
196 if( coff_file
->neps
+ 1 >= coff_file
->neps_alloc
)
198 coff_file
->neps_alloc
+= 10;
199 coff_file
->entries
= (struct name_hash
**)
200 DBG_realloc(coff_file
->entries
,
201 coff_file
->neps_alloc
* sizeof(struct name_hash
*));
203 coff_file
->entries
[coff_file
->neps
++] = sym
;
206 static enum DbgInfoLoad
DEBUG_ProcessCoff( DBG_MODULE
*module
, LPBYTE root
)
208 PIMAGE_AUX_SYMBOL aux
;
209 PIMAGE_COFF_SYMBOLS_HEADER coff
;
210 PIMAGE_LINENUMBER coff_linetab
;
211 PIMAGE_LINENUMBER linepnt
;
213 PIMAGE_SYMBOL coff_sym
;
214 PIMAGE_SYMBOL coff_symbols
;
215 struct CoffFileSet coff_files
;
216 int curr_file_idx
= -1;
225 enum DbgInfoLoad dil
= DIL_ERROR
;
227 DEBUG_Printf(DBG_CHN_TRACE
, "Processing COFF symbols...\n");
229 assert(sizeof(IMAGE_SYMBOL
) == IMAGE_SIZEOF_SYMBOL
);
230 assert(sizeof(IMAGE_LINENUMBER
) == IMAGE_SIZEOF_LINENUMBER
);
232 coff_files
.files
= NULL
;
233 coff_files
.nfiles
= coff_files
.nfiles_alloc
= 0;
235 coff
= (PIMAGE_COFF_SYMBOLS_HEADER
) root
;
237 coff_symbols
= (PIMAGE_SYMBOL
) ((unsigned int) coff
+ coff
->LvaToFirstSymbol
);
238 coff_linetab
= (PIMAGE_LINENUMBER
) ((unsigned int) coff
+ coff
->LvaToFirstLinenumber
);
239 coff_strtab
= (char *) (coff_symbols
+ coff
->NumberOfSymbols
);
243 new_value
.cookie
= DV_TARGET
;
244 new_value
.type
= NULL
;
246 for(i
=0; i
< coff
->NumberOfSymbols
; i
++ )
248 coff_sym
= coff_symbols
+ i
;
249 naux
= coff_sym
->NumberOfAuxSymbols
;
251 if( coff_sym
->StorageClass
== IMAGE_SYM_CLASS_FILE
)
253 curr_file_idx
= DEBUG_AddCoffFile( &coff_files
, (char *) (coff_sym
+ 1) );
254 DEBUG_Printf(DBG_CHN_TRACE
,"New file %s\n", coff_files
.files
[curr_file_idx
].filename
);
259 if (curr_file_idx
< 0) {
260 assert(coff_files
.nfiles
== 0 && coff_files
.nfiles_alloc
== 0);
261 curr_file_idx
= DEBUG_AddCoffFile( &coff_files
, "<none>" );
262 DEBUG_Printf(DBG_CHN_TRACE
,"New file %s\n", coff_files
.files
[curr_file_idx
].filename
);
266 * This guy marks the size and location of the text section
267 * for the current file. We need to keep track of this so
268 * we can figure out what file the different global functions
271 if( (coff_sym
->StorageClass
== IMAGE_SYM_CLASS_STATIC
)
273 && (coff_sym
->Type
== 0)
274 && (coff_sym
->SectionNumber
== 1) )
276 aux
= (PIMAGE_AUX_SYMBOL
) (coff_sym
+ 1);
278 if( coff_files
.files
[curr_file_idx
].linetab_offset
!= -1 )
281 * Save this so we can still get the old name.
283 const char* fn
= coff_files
.files
[curr_file_idx
].filename
;
286 DEBUG_Printf(DBG_CHN_TRACE
, "Duplicating sect from %s: %lx %x %x %d %d\n",
287 coff_files
.files
[curr_file_idx
].filename
,
289 aux
->Section
.NumberOfRelocations
,
290 aux
->Section
.NumberOfLinenumbers
,
292 aux
->Section
.Selection
);
293 DEBUG_Printf(DBG_CHN_TRACE
, "More sect %d %s %08lx %d %d %d\n",
294 coff_sym
->SectionNumber
,
295 DEBUG_GetCoffName( coff_sym
, coff_strtab
),
298 coff_sym
->StorageClass
,
299 coff_sym
->NumberOfAuxSymbols
);
303 * Duplicate the file entry. We have no way to describe
304 * multiple text sections in our current way of handling things.
306 DEBUG_AddCoffFile( &coff_files
, fn
);
311 DEBUG_Printf(DBG_CHN_TRACE
, "New text sect from %s: %lx %x %x %d %d\n",
312 coff_files
.files
[curr_file_idx
].filename
,
314 aux
->Section
.NumberOfRelocations
,
315 aux
->Section
.NumberOfLinenumbers
,
317 aux
->Section
.Selection
);
321 if( coff_files
.files
[curr_file_idx
].startaddr
> coff_sym
->Value
)
323 coff_files
.files
[curr_file_idx
].startaddr
= coff_sym
->Value
;
326 if( coff_files
.files
[curr_file_idx
].endaddr
< coff_sym
->Value
+ aux
->Section
.Length
)
328 coff_files
.files
[curr_file_idx
].endaddr
= coff_sym
->Value
+ aux
->Section
.Length
;
331 coff_files
.files
[curr_file_idx
].linetab_offset
= linetab_indx
;
332 coff_files
.files
[curr_file_idx
].linecnt
= aux
->Section
.NumberOfLinenumbers
;
333 linetab_indx
+= aux
->Section
.NumberOfLinenumbers
;
338 if( (coff_sym
->StorageClass
== IMAGE_SYM_CLASS_STATIC
)
340 && (coff_sym
->SectionNumber
== 1) )
342 DWORD base
= module
->msc_info
->sectp
[coff_sym
->SectionNumber
- 1].VirtualAddress
;
344 * This is a normal static function when naux == 0.
345 * Just register it. The current file is the correct
346 * one in this instance.
348 nampnt
= DEBUG_GetCoffName( coff_sym
, coff_strtab
);
350 new_value
.addr
.seg
= 0;
351 new_value
.addr
.off
= (int) ((char *)module
->load_addr
+ base
+ coff_sym
->Value
);
354 DEBUG_Printf(DBG_CHN_TRACE
,"\tAdding static symbol %s\n", nampnt
);
357 /* FIXME: was adding symbol to this_file ??? */
358 DEBUG_AddCoffSymbol( &coff_files
.files
[curr_file_idx
],
359 DEBUG_AddSymbol( nampnt
, &new_value
,
360 coff_files
.files
[curr_file_idx
].filename
,
361 SYM_WIN32
| SYM_FUNC
) );
366 if( (coff_sym
->StorageClass
== IMAGE_SYM_CLASS_EXTERNAL
)
367 && ISFCN(coff_sym
->Type
)
368 && (coff_sym
->SectionNumber
> 0) )
370 const char* this_file
= NULL
;
371 DWORD base
= module
->msc_info
->sectp
[coff_sym
->SectionNumber
- 1].VirtualAddress
;
372 nampnt
= DEBUG_GetCoffName( coff_sym
, coff_strtab
);
374 new_value
.addr
.seg
= 0;
375 new_value
.addr
.off
= (int) ((char *)module
->load_addr
+ base
+ coff_sym
->Value
);
378 DEBUG_Printf(DBG_CHN_TRACE
, "%d: %lx %s\n", i
, new_value
.addr
.off
, nampnt
);
380 DEBUG_Printf(DBG_CHN_TRACE
,"\tAdding global symbol %s (sect=%s)\n",
381 nampnt
, MSC_INFO(module
)->sectp
[coff_sym
->SectionNumber
- 1].Name
);
385 * Now we need to figure out which file this guy belongs to.
387 for(j
=0; j
< coff_files
.nfiles
; j
++)
389 if( coff_files
.files
[j
].startaddr
<= base
+ coff_sym
->Value
390 && coff_files
.files
[j
].endaddr
> base
+ coff_sym
->Value
)
392 this_file
= coff_files
.files
[j
].filename
;
396 if (j
< coff_files
.nfiles
) {
397 DEBUG_AddCoffSymbol( &coff_files
.files
[j
],
398 DEBUG_AddSymbol( nampnt
, &new_value
, this_file
, SYM_WIN32
| SYM_FUNC
) );
400 DEBUG_AddSymbol( nampnt
, &new_value
, NULL
, SYM_WIN32
| SYM_FUNC
);
406 if( (coff_sym
->StorageClass
== IMAGE_SYM_CLASS_EXTERNAL
)
407 && (coff_sym
->SectionNumber
> 0) )
409 DWORD base
= module
->msc_info
->sectp
[coff_sym
->SectionNumber
- 1].VirtualAddress
;
411 * Similar to above, but for the case of data symbols.
412 * These aren't treated as entrypoints.
414 nampnt
= DEBUG_GetCoffName( coff_sym
, coff_strtab
);
416 new_value
.addr
.seg
= 0;
417 new_value
.addr
.off
= (int) ((char *)module
->load_addr
+ base
+ coff_sym
->Value
);
420 DEBUG_Printf(DBG_CHN_TRACE
, "%d: %lx %s\n", i
, new_value
.addr
.off
, nampnt
);
422 DEBUG_Printf(DBG_CHN_TRACE
,"\tAdding global data symbol %s\n", nampnt
);
426 * Now we need to figure out which file this guy belongs to.
428 DEBUG_AddSymbol( nampnt
, &new_value
, NULL
, SYM_WIN32
| SYM_DATA
);
433 if( (coff_sym
->StorageClass
== IMAGE_SYM_CLASS_STATIC
)
437 * Ignore these. They don't have anything to do with
445 DEBUG_Printf(DBG_CHN_TRACE
,"Skipping unknown entry '%s' %d %d %d\n",
446 DEBUG_GetCoffName( coff_sym
, coff_strtab
),
447 coff_sym
->StorageClass
, coff_sym
->SectionNumber
, naux
);
451 * For now, skip past the aux entries.
458 * OK, we now should have a list of files, and we should have a list
459 * of entrypoints. We need to sort the entrypoints so that we are
460 * able to tie the line numbers with the given functions within the
463 if( coff_files
.files
!= NULL
)
465 for(j
=0; j
< coff_files
.nfiles
; j
++)
467 if( coff_files
.files
[j
].entries
!= NULL
)
469 qsort(coff_files
.files
[j
].entries
, coff_files
.files
[j
].neps
,
470 sizeof(struct name_hash
*), DEBUG_cmp_sym
);
475 * Now pick apart the line number tables, and attach the entries
476 * to the given functions.
478 for(j
=0; j
< coff_files
.nfiles
; j
++)
481 if( coff_files
.files
[j
].neps
!= 0 )
482 for(k
=0; k
< coff_files
.files
[j
].linecnt
; k
++)
484 linepnt
= coff_linetab
+ coff_files
.files
[j
].linetab_offset
+ k
;
486 * If we have spilled onto the next entrypoint, then
491 if (l
+1 >= coff_files
.files
[j
].neps
) break;
492 DEBUG_GetSymbolAddr(coff_files
.files
[j
].entries
[l
+1], &new_value
.addr
);
493 if( (((unsigned int)module
->load_addr
+
494 linepnt
->Type
.VirtualAddress
) >= new_value
.addr
.off
) )
501 * Add the line number. This is always relative to the
502 * start of the function, so we need to subtract that offset
505 DEBUG_GetSymbolAddr(coff_files
.files
[j
].entries
[l
], &new_value
.addr
);
506 DEBUG_AddLineNumber(coff_files
.files
[j
].entries
[l
],
508 (unsigned int) module
->load_addr
509 + linepnt
->Type
.VirtualAddress
510 - new_value
.addr
.off
);
517 if( coff_files
.files
!= NULL
)
519 for(j
=0; j
< coff_files
.nfiles
; j
++)
521 if( coff_files
.files
[j
].entries
!= NULL
)
523 DBG_free(coff_files
.files
[j
].entries
);
526 DBG_free(coff_files
.files
);
535 /*========================================================================
536 * Process CodeView type information.
543 unsigned short int len
;
549 unsigned short int len
;
553 unsigned char variant
[1];
558 unsigned short int len
;
560 unsigned int datatype
;
561 unsigned int attribute
;
562 unsigned char variant
[1];
567 unsigned short int len
;
570 unsigned char bitoff
;
576 unsigned short int len
;
580 unsigned char bitoff
;
585 unsigned short int len
;
589 unsigned short int arrlen
; /* numeric leaf */
591 unsigned char name
[1];
597 unsigned short int len
;
599 unsigned int elemtype
;
600 unsigned int idxtype
;
601 unsigned short int arrlen
; /* numeric leaf */
603 unsigned char name
[1];
609 unsigned short int len
;
616 unsigned short int structlen
; /* numeric leaf */
618 unsigned char name
[1];
624 unsigned short int len
;
628 unsigned int fieldlist
;
629 unsigned int derived
;
631 unsigned short int structlen
; /* numeric leaf */
633 unsigned char name
[1];
639 unsigned short int len
;
644 unsigned short int un_len
; /* numeric leaf */
646 unsigned char name
[1];
652 unsigned short int len
;
656 unsigned int fieldlist
;
657 unsigned short int un_len
; /* numeric leaf */
659 unsigned char name
[1];
665 unsigned short int len
;
671 unsigned char name
[1];
676 unsigned short int len
;
682 unsigned char name
[1];
687 unsigned short int len
;
689 unsigned char list
[1];
693 union codeview_fieldtype
705 unsigned short int offset
; /* numeric leaf */
713 unsigned short int offset
; /* numeric leaf */
722 unsigned short int vbpoff
; /* numeric leaf */
724 unsigned short int vboff
; /* numeric leaf */
734 unsigned short int vbpoff
; /* numeric leaf */
736 unsigned short int vboff
; /* numeric leaf */
744 unsigned short int value
; /* numeric leaf */
746 unsigned char name
[1];
754 unsigned char name
[1];
762 unsigned char name
[1];
770 unsigned short int offset
; /* numeric leaf */
772 unsigned char name
[1];
781 unsigned short int offset
; /* numeric leaf */
783 unsigned char name
[1];
792 unsigned char name
[1];
800 unsigned char name
[1];
808 unsigned char name
[1];
816 unsigned char name
[1];
823 unsigned char name
[1];
831 unsigned char name
[1];
866 unsigned char name
[1];
873 unsigned int vtab_offset
;
874 unsigned char name
[1];
882 unsigned char name
[1];
889 unsigned int vtab_offset
;
890 unsigned char name
[1];
913 unsigned char name
[1];
921 unsigned char name
[1];
929 unsigned char name
[1];
935 * This covers the basic datatypes that VC++ seems to be using these days.
936 * 32 bit mode only. There are additional numbers for the pointers in 16
937 * bit mode. There are many other types listed in the documents, but these
938 * are apparently not used by the compiler, or represent pointer types
941 #define T_NOTYPE 0x0000 /* Notype */
942 #define T_ABS 0x0001 /* Abs */
943 #define T_VOID 0x0003 /* Void */
944 #define T_CHAR 0x0010 /* signed char */
945 #define T_SHORT 0x0011 /* short */
946 #define T_LONG 0x0012 /* long */
947 #define T_QUAD 0x0013 /* long long */
948 #define T_UCHAR 0x0020 /* unsigned char */
949 #define T_USHORT 0x0021 /* unsigned short */
950 #define T_ULONG 0x0022 /* unsigned long */
951 #define T_UQUAD 0x0023 /* unsigned long long */
952 #define T_REAL32 0x0040 /* float */
953 #define T_REAL64 0x0041 /* double */
954 #define T_RCHAR 0x0070 /* real char */
955 #define T_WCHAR 0x0071 /* wide char */
956 #define T_INT4 0x0074 /* int */
957 #define T_UINT4 0x0075 /* unsigned int */
959 #define T_32PVOID 0x0403 /* 32 bit near pointer to void */
960 #define T_32PCHAR 0x0410 /* 16:32 near pointer to signed char */
961 #define T_32PSHORT 0x0411 /* 16:32 near pointer to short */
962 #define T_32PLONG 0x0412 /* 16:32 near pointer to int */
963 #define T_32PQUAD 0x0413 /* 16:32 near pointer to long long */
964 #define T_32PUCHAR 0x0420 /* 16:32 near pointer to unsigned char */
965 #define T_32PUSHORT 0x0421 /* 16:32 near pointer to unsigned short */
966 #define T_32PULONG 0x0422 /* 16:32 near pointer to unsigned int */
967 #define T_32PUQUAD 0x0423 /* 16:32 near pointer to long long */
968 #define T_32PREAL32 0x0440 /* 16:32 near pointer to float */
969 #define T_32PREAL64 0x0441 /* 16:32 near pointer to float */
970 #define T_32PRCHAR 0x0470 /* 16:32 near pointer to real char */
971 #define T_32PWCHAR 0x0471 /* 16:32 near pointer to real char */
972 #define T_32PINT4 0x0474 /* 16:32 near pointer to int */
973 #define T_32PUINT4 0x0475 /* 16:32 near pointer to unsigned int */
976 #define LF_MODIFIER 0x0001
977 #define LF_POINTER 0x0002
978 #define LF_ARRAY 0x0003
979 #define LF_CLASS 0x0004
980 #define LF_STRUCTURE 0x0005
981 #define LF_UNION 0x0006
982 #define LF_ENUM 0x0007
983 #define LF_PROCEDURE 0x0008
984 #define LF_MFUNCTION 0x0009
985 #define LF_VTSHAPE 0x000a
986 #define LF_COBOL0 0x000b
987 #define LF_COBOL1 0x000c
988 #define LF_BARRAY 0x000d
989 #define LF_LABEL 0x000e
990 #define LF_NULL 0x000f
991 #define LF_NOTTRAN 0x0010
992 #define LF_DIMARRAY 0x0011
993 #define LF_VFTPATH 0x0012
994 #define LF_PRECOMP 0x0013
995 #define LF_ENDPRECOMP 0x0014
996 #define LF_OEM 0x0015
997 #define LF_TYPESERVER 0x0016
999 #define LF_MODIFIER_32 0x1001 /* variants with new 32-bit type indices */
1000 #define LF_POINTER_32 0x1002
1001 #define LF_ARRAY_32 0x1003
1002 #define LF_CLASS_32 0x1004
1003 #define LF_STRUCTURE_32 0x1005
1004 #define LF_UNION_32 0x1006
1005 #define LF_ENUM_32 0x1007
1006 #define LF_PROCEDURE_32 0x1008
1007 #define LF_MFUNCTION_32 0x1009
1008 #define LF_COBOL0_32 0x100a
1009 #define LF_BARRAY_32 0x100b
1010 #define LF_DIMARRAY_32 0x100c
1011 #define LF_VFTPATH_32 0x100d
1012 #define LF_PRECOMP_32 0x100e
1013 #define LF_OEM_32 0x100f
1015 #define LF_SKIP 0x0200
1016 #define LF_ARGLIST 0x0201
1017 #define LF_DEFARG 0x0202
1018 #define LF_LIST 0x0203
1019 #define LF_FIELDLIST 0x0204
1020 #define LF_DERIVED 0x0205
1021 #define LF_BITFIELD 0x0206
1022 #define LF_METHODLIST 0x0207
1023 #define LF_DIMCONU 0x0208
1024 #define LF_DIMCONLU 0x0209
1025 #define LF_DIMVARU 0x020a
1026 #define LF_DIMVARLU 0x020b
1027 #define LF_REFSYM 0x020c
1029 #define LF_SKIP_32 0x1200 /* variants with new 32-bit type indices */
1030 #define LF_ARGLIST_32 0x1201
1031 #define LF_DEFARG_32 0x1202
1032 #define LF_FIELDLIST_32 0x1203
1033 #define LF_DERIVED_32 0x1204
1034 #define LF_BITFIELD_32 0x1205
1035 #define LF_METHODLIST_32 0x1206
1036 #define LF_DIMCONU_32 0x1207
1037 #define LF_DIMCONLU_32 0x1208
1038 #define LF_DIMVARU_32 0x1209
1039 #define LF_DIMVARLU_32 0x120a
1041 #define LF_BCLASS 0x0400
1042 #define LF_VBCLASS 0x0401
1043 #define LF_IVBCLASS 0x0402
1044 #define LF_ENUMERATE 0x0403
1045 #define LF_FRIENDFCN 0x0404
1046 #define LF_INDEX 0x0405
1047 #define LF_MEMBER 0x0406
1048 #define LF_STMEMBER 0x0407
1049 #define LF_METHOD 0x0408
1050 #define LF_NESTTYPE 0x0409
1051 #define LF_VFUNCTAB 0x040a
1052 #define LF_FRIENDCLS 0x040b
1053 #define LF_ONEMETHOD 0x040c
1054 #define LF_VFUNCOFF 0x040d
1055 #define LF_NESTTYPEEX 0x040e
1056 #define LF_MEMBERMODIFY 0x040f
1058 #define LF_BCLASS_32 0x1400 /* variants with new 32-bit type indices */
1059 #define LF_VBCLASS_32 0x1401
1060 #define LF_IVBCLASS_32 0x1402
1061 #define LF_FRIENDFCN_32 0x1403
1062 #define LF_INDEX_32 0x1404
1063 #define LF_MEMBER_32 0x1405
1064 #define LF_STMEMBER_32 0x1406
1065 #define LF_METHOD_32 0x1407
1066 #define LF_NESTTYPE_32 0x1408
1067 #define LF_VFUNCTAB_32 0x1409
1068 #define LF_FRIENDCLS_32 0x140a
1069 #define LF_ONEMETHOD_32 0x140b
1070 #define LF_VFUNCOFF_32 0x140c
1071 #define LF_NESTTYPEEX_32 0x140d
1073 #define LF_NUMERIC 0x8000 /* numeric leaf types */
1074 #define LF_CHAR 0x8000
1075 #define LF_SHORT 0x8001
1076 #define LF_USHORT 0x8002
1077 #define LF_LONG 0x8003
1078 #define LF_ULONG 0x8004
1079 #define LF_REAL32 0x8005
1080 #define LF_REAL64 0x8006
1081 #define LF_REAL80 0x8007
1082 #define LF_REAL128 0x8008
1083 #define LF_QUADWORD 0x8009
1084 #define LF_UQUADWORD 0x800a
1085 #define LF_REAL48 0x800b
1086 #define LF_COMPLEX32 0x800c
1087 #define LF_COMPLEX64 0x800d
1088 #define LF_COMPLEX80 0x800e
1089 #define LF_COMPLEX128 0x800f
1090 #define LF_VARSTRING 0x8010
1094 #define MAX_BUILTIN_TYPES 0x480
1095 static struct datatype
* cv_basic_types
[MAX_BUILTIN_TYPES
];
1096 static unsigned int num_cv_defined_types
= 0;
1097 static struct datatype
**cv_defined_types
= NULL
;
1100 DEBUG_InitCVDataTypes(void)
1103 * These are the common builtin types that are used by VC++.
1105 cv_basic_types
[T_NOTYPE
] = NULL
;
1106 cv_basic_types
[T_ABS
] = NULL
;
1107 cv_basic_types
[T_VOID
] = DEBUG_GetBasicType(DT_BASIC_VOID
);
1108 cv_basic_types
[T_CHAR
] = DEBUG_GetBasicType(DT_BASIC_CHAR
);
1109 cv_basic_types
[T_SHORT
] = DEBUG_GetBasicType(DT_BASIC_SHORTINT
);
1110 cv_basic_types
[T_LONG
] = DEBUG_GetBasicType(DT_BASIC_LONGINT
);
1111 cv_basic_types
[T_QUAD
] = DEBUG_GetBasicType(DT_BASIC_LONGLONGINT
);
1112 cv_basic_types
[T_UCHAR
] = DEBUG_GetBasicType(DT_BASIC_UCHAR
);
1113 cv_basic_types
[T_USHORT
] = DEBUG_GetBasicType(DT_BASIC_USHORTINT
);
1114 cv_basic_types
[T_ULONG
] = DEBUG_GetBasicType(DT_BASIC_ULONGINT
);
1115 cv_basic_types
[T_UQUAD
] = DEBUG_GetBasicType(DT_BASIC_ULONGLONGINT
);
1116 cv_basic_types
[T_REAL32
] = DEBUG_GetBasicType(DT_BASIC_FLOAT
);
1117 cv_basic_types
[T_REAL64
] = DEBUG_GetBasicType(DT_BASIC_DOUBLE
);
1118 cv_basic_types
[T_RCHAR
] = DEBUG_GetBasicType(DT_BASIC_CHAR
);
1119 cv_basic_types
[T_WCHAR
] = DEBUG_GetBasicType(DT_BASIC_SHORTINT
);
1120 cv_basic_types
[T_INT4
] = DEBUG_GetBasicType(DT_BASIC_INT
);
1121 cv_basic_types
[T_UINT4
] = DEBUG_GetBasicType(DT_BASIC_UINT
);
1123 cv_basic_types
[T_32PVOID
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_VOID
]);
1124 cv_basic_types
[T_32PCHAR
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_CHAR
]);
1125 cv_basic_types
[T_32PSHORT
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_SHORT
]);
1126 cv_basic_types
[T_32PLONG
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_LONG
]);
1127 cv_basic_types
[T_32PQUAD
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_QUAD
]);
1128 cv_basic_types
[T_32PUCHAR
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_UCHAR
]);
1129 cv_basic_types
[T_32PUSHORT
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_USHORT
]);
1130 cv_basic_types
[T_32PULONG
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_ULONG
]);
1131 cv_basic_types
[T_32PUQUAD
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_UQUAD
]);
1132 cv_basic_types
[T_32PREAL32
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_REAL32
]);
1133 cv_basic_types
[T_32PREAL64
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_REAL64
]);
1134 cv_basic_types
[T_32PRCHAR
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_RCHAR
]);
1135 cv_basic_types
[T_32PWCHAR
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_WCHAR
]);
1136 cv_basic_types
[T_32PINT4
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_INT4
]);
1137 cv_basic_types
[T_32PUINT4
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_UINT4
]);
1142 numeric_leaf( int *value
, unsigned short int *leaf
)
1144 unsigned short int type
= *leaf
++;
1147 if ( type
< LF_NUMERIC
)
1157 *value
= *(char *)leaf
;
1162 *value
= *(short *)leaf
;
1167 *value
= *(unsigned short *)leaf
;
1172 *value
= *(int *)leaf
;
1177 *value
= *(unsigned int *)leaf
;
1183 *value
= 0; /* FIXME */
1188 *value
= 0; /* FIXME */
1193 *value
= 0; /* FIXME */
1198 *value
= 0; /* FIXME */
1203 *value
= 0; /* FIXME */
1208 *value
= 0; /* FIXME */
1213 *value
= 0; /* FIXME */
1218 *value
= 0; /* FIXME */
1223 *value
= 0; /* FIXME */
1228 *value
= 0; /* FIXME */
1232 length
+= 2 + *leaf
;
1233 *value
= 0; /* FIXME */
1237 DEBUG_Printf( DBG_CHN_MESG
, "Unknown numeric leaf type %04x\n", type
);
1247 terminate_string( unsigned char *name
)
1249 static char symname
[256];
1251 int namelen
= name
[0];
1252 assert( namelen
>= 0 && namelen
< 256 );
1254 memcpy( symname
, name
+1, namelen
);
1255 symname
[namelen
] = '\0';
1257 if ( !*symname
|| strcmp( symname
, "__unnamed" ) == 0 )
1264 struct datatype
* DEBUG_GetCVType(unsigned int typeno
)
1266 struct datatype
* dt
= NULL
;
1269 * Convert Codeview type numbers into something we can grok internally.
1270 * Numbers < 0x1000 are all fixed builtin types. Numbers from 0x1000 and
1271 * up are all user defined (structs, etc).
1273 if ( typeno
< 0x1000 )
1275 if ( typeno
< MAX_BUILTIN_TYPES
)
1276 dt
= cv_basic_types
[typeno
];
1280 if ( typeno
- 0x1000 < num_cv_defined_types
)
1281 dt
= cv_defined_types
[typeno
- 0x1000];
1288 DEBUG_AddCVType( unsigned int typeno
, struct datatype
*dt
)
1290 while ( typeno
- 0x1000 >= num_cv_defined_types
)
1292 num_cv_defined_types
+= 0x100;
1293 cv_defined_types
= (struct datatype
**)
1294 DBG_realloc( cv_defined_types
,
1295 num_cv_defined_types
* sizeof(struct datatype
*) );
1297 memset( cv_defined_types
+ num_cv_defined_types
- 0x100,
1299 0x100 * sizeof(struct datatype
*) );
1301 if ( cv_defined_types
== NULL
)
1305 cv_defined_types
[ typeno
- 0x1000 ] = dt
;
1310 DEBUG_ClearTypeTable( void )
1312 if ( cv_defined_types
)
1313 DBG_free( cv_defined_types
);
1315 cv_defined_types
= NULL
;
1316 num_cv_defined_types
= 0;
1320 DEBUG_AddCVType_Pointer( unsigned int typeno
, unsigned int datatype
)
1322 struct datatype
*dt
=
1323 DEBUG_FindOrMakePointerType( DEBUG_GetCVType( datatype
) );
1325 return DEBUG_AddCVType( typeno
, dt
);
1329 DEBUG_AddCVType_Array( unsigned int typeno
, char *name
,
1330 unsigned int elemtype
, unsigned int arr_len
)
1332 struct datatype
*dt
= DEBUG_NewDataType( DT_ARRAY
, name
);
1333 struct datatype
*elem
= DEBUG_GetCVType( elemtype
);
1334 unsigned int elem_size
= elem
? DEBUG_GetObjectSize( elem
) : 0;
1335 unsigned int arr_max
= elem_size
? arr_len
/ elem_size
: 0;
1337 DEBUG_SetArrayParams( dt
, 0, arr_max
, elem
);
1338 return DEBUG_AddCVType( typeno
, dt
);
1342 DEBUG_AddCVType_Bitfield( unsigned int typeno
,
1343 unsigned int bitoff
, unsigned int nbits
,
1344 unsigned int basetype
)
1346 struct datatype
*dt
= DEBUG_NewDataType( DT_BITFIELD
, NULL
);
1347 struct datatype
*base
= DEBUG_GetCVType( basetype
);
1349 DEBUG_SetBitfieldParams( dt
, bitoff
, nbits
, base
);
1350 return DEBUG_AddCVType( typeno
, dt
);
1354 DEBUG_AddCVType_EnumFieldList( unsigned int typeno
, unsigned char *list
, int len
)
1356 struct datatype
*dt
= DEBUG_NewDataType( DT_ENUM
, NULL
);
1357 unsigned char *ptr
= list
;
1359 while ( ptr
- list
< len
)
1361 union codeview_fieldtype
*type
= (union codeview_fieldtype
*)ptr
;
1363 if ( *ptr
>= 0xf0 ) /* LF_PAD... */
1369 switch ( type
->generic
.id
)
1373 int value
, vlen
= numeric_leaf( &value
, &type
->enumerate
.value
);
1374 unsigned char *name
= (unsigned char *)&type
->enumerate
.value
+ vlen
;
1376 DEBUG_AddStructElement( dt
, terminate_string( name
),
1379 ptr
+= 2 + 2 + vlen
+ (1 + name
[0]);
1384 DEBUG_Printf( DBG_CHN_MESG
, "Unhandled type %04x in ENUM field list\n",
1390 return DEBUG_AddCVType( typeno
, dt
);
1394 DEBUG_AddCVType_StructFieldList( unsigned int typeno
, unsigned char *list
, int len
)
1396 struct datatype
*dt
= DEBUG_NewDataType( DT_STRUCT
, NULL
);
1397 unsigned char *ptr
= list
;
1399 while ( ptr
- list
< len
)
1401 union codeview_fieldtype
*type
= (union codeview_fieldtype
*)ptr
;
1403 if ( *ptr
>= 0xf0 ) /* LF_PAD... */
1409 switch ( type
->generic
.id
)
1413 int offset
, olen
= numeric_leaf( &offset
, &type
->bclass
.offset
);
1415 /* FIXME: ignored for now */
1417 ptr
+= 2 + 2 + 2 + olen
;
1423 int offset
, olen
= numeric_leaf( &offset
, &type
->bclass32
.offset
);
1425 /* FIXME: ignored for now */
1427 ptr
+= 2 + 2 + 4 + olen
;
1434 int vbpoff
, vbplen
= numeric_leaf( &vbpoff
, &type
->vbclass
.vbpoff
);
1435 unsigned short int *p_vboff
= (unsigned short int *)((char *)&type
->vbclass
.vbpoff
+ vbpoff
);
1436 int vpoff
, vplen
= numeric_leaf( &vpoff
, p_vboff
);
1438 /* FIXME: ignored for now */
1440 ptr
+= 2 + 2 + 2 + 2 + vbplen
+ vplen
;
1445 case LF_IVBCLASS_32
:
1447 int vbpoff
, vbplen
= numeric_leaf( &vbpoff
, &type
->vbclass32
.vbpoff
);
1448 unsigned short int *p_vboff
= (unsigned short int *)((char *)&type
->vbclass32
.vbpoff
+ vbpoff
);
1449 int vpoff
, vplen
= numeric_leaf( &vpoff
, p_vboff
);
1451 /* FIXME: ignored for now */
1453 ptr
+= 2 + 2 + 4 + 4 + vbplen
+ vplen
;
1459 int offset
, olen
= numeric_leaf( &offset
, &type
->member
.offset
);
1460 unsigned char *name
= (unsigned char *)&type
->member
.offset
+ olen
;
1462 struct datatype
*subtype
= DEBUG_GetCVType( type
->member
.type
);
1463 int elem_size
= subtype
? DEBUG_GetObjectSize( subtype
) : 0;
1465 DEBUG_AddStructElement( dt
, terminate_string( name
),
1466 subtype
, offset
<< 3, elem_size
<< 3 );
1468 ptr
+= 2 + 2 + 2 + olen
+ (1 + name
[0]);
1474 int offset
, olen
= numeric_leaf( &offset
, &type
->member32
.offset
);
1475 unsigned char *name
= (unsigned char *)&type
->member32
.offset
+ olen
;
1477 struct datatype
*subtype
= DEBUG_GetCVType( type
->member32
.type
);
1478 int elem_size
= subtype
? DEBUG_GetObjectSize( subtype
) : 0;
1480 DEBUG_AddStructElement( dt
, terminate_string( name
),
1481 subtype
, offset
<< 3, elem_size
<< 3 );
1483 ptr
+= 2 + 2 + 4 + olen
+ (1 + name
[0]);
1488 /* FIXME: ignored for now */
1489 ptr
+= 2 + 2 + 2 + (1 + type
->stmember
.name
[0]);
1492 case LF_STMEMBER_32
:
1493 /* FIXME: ignored for now */
1494 ptr
+= 2 + 4 + 2 + (1 + type
->stmember32
.name
[0]);
1498 /* FIXME: ignored for now */
1499 ptr
+= 2 + 2 + 2 + (1 + type
->method
.name
[0]);
1503 /* FIXME: ignored for now */
1504 ptr
+= 2 + 2 + 4 + (1 + type
->method32
.name
[0]);
1508 /* FIXME: ignored for now */
1509 ptr
+= 2 + 2 + (1 + type
->nesttype
.name
[0]);
1512 case LF_NESTTYPE_32
:
1513 /* FIXME: ignored for now */
1514 ptr
+= 2 + 2 + 4 + (1 + type
->nesttype32
.name
[0]);
1518 /* FIXME: ignored for now */
1522 case LF_VFUNCTAB_32
:
1523 /* FIXME: ignored for now */
1528 /* FIXME: ignored for now */
1529 switch ( (type
->onemethod
.attribute
>> 2) & 7 )
1531 case 4: case 6: /* (pure) introducing virtual method */
1532 ptr
+= 2 + 2 + 2 + 4 + (1 + type
->onemethod_virt
.name
[0]);
1536 ptr
+= 2 + 2 + 2 + (1 + type
->onemethod
.name
[0]);
1541 case LF_ONEMETHOD_32
:
1542 /* FIXME: ignored for now */
1543 switch ( (type
->onemethod32
.attribute
>> 2) & 7 )
1545 case 4: case 6: /* (pure) introducing virtual method */
1546 ptr
+= 2 + 2 + 4 + 4 + (1 + type
->onemethod32_virt
.name
[0]);
1550 ptr
+= 2 + 2 + 4 + (1 + type
->onemethod32
.name
[0]);
1556 DEBUG_Printf( DBG_CHN_MESG
, "Unhandled type %04x in STRUCT field list\n",
1562 return DEBUG_AddCVType( typeno
, dt
);
1566 DEBUG_AddCVType_Enum( unsigned int typeno
, char *name
, unsigned int fieldlist
)
1568 struct datatype
*dt
= DEBUG_NewDataType( DT_ENUM
, name
);
1569 struct datatype
*list
= DEBUG_GetCVType( fieldlist
);
1572 if(DEBUG_CopyFieldlist( dt
, list
) == FALSE
)
1575 return DEBUG_AddCVType( typeno
, dt
);
1579 DEBUG_AddCVType_Struct( unsigned int typeno
, char *name
, int structlen
, unsigned int fieldlist
)
1581 struct datatype
*dt
= DEBUG_NewDataType( DT_STRUCT
, name
);
1582 struct datatype
*list
= DEBUG_GetCVType( fieldlist
);
1586 DEBUG_SetStructSize( dt
, structlen
);
1587 if(DEBUG_CopyFieldlist( dt
, list
) == FALSE
)
1591 return DEBUG_AddCVType( typeno
, dt
);
1595 DEBUG_ParseTypeTable( char *table
, int len
)
1597 unsigned int curr_type
= 0x1000;
1600 while ( ptr
- table
< len
)
1602 union codeview_type
*type
= (union codeview_type
*) ptr
;
1605 switch ( type
->generic
.id
)
1608 retv
= DEBUG_AddCVType_Pointer( curr_type
, type
->pointer
.datatype
);
1611 retv
= DEBUG_AddCVType_Pointer( curr_type
, type
->pointer32
.datatype
);
1616 int arrlen
, alen
= numeric_leaf( &arrlen
, &type
->array
.arrlen
);
1617 unsigned char *name
= (unsigned char *)&type
->array
.arrlen
+ alen
;
1619 retv
= DEBUG_AddCVType_Array( curr_type
, terminate_string( name
),
1620 type
->array
.elemtype
, arrlen
);
1625 int arrlen
, alen
= numeric_leaf( &arrlen
, &type
->array32
.arrlen
);
1626 unsigned char *name
= (unsigned char *)&type
->array32
.arrlen
+ alen
;
1628 retv
= DEBUG_AddCVType_Array( curr_type
, terminate_string( name
),
1629 type
->array32
.elemtype
, type
->array32
.arrlen
);
1634 retv
= DEBUG_AddCVType_Bitfield( curr_type
, type
->bitfield
.bitoff
,
1635 type
->bitfield
.nbits
,
1636 type
->bitfield
.type
);
1638 case LF_BITFIELD_32
:
1639 retv
= DEBUG_AddCVType_Bitfield( curr_type
, type
->bitfield32
.bitoff
,
1640 type
->bitfield32
.nbits
,
1641 type
->bitfield32
.type
);
1645 case LF_FIELDLIST_32
:
1648 * A 'field list' is a CodeView-specific data type which doesn't
1649 * directly correspond to any high-level data type. It is used
1650 * to hold the collection of members of a struct, class, union
1651 * or enum type. The actual definition of that type will follow
1652 * later, and refer to the field list definition record.
1654 * As we don't have a field list type ourselves, we look ahead
1655 * in the field list to try to find out whether this field list
1656 * will be used for an enum or struct type, and create a dummy
1657 * type of the corresponding sort. Later on, the definition of
1658 * the 'real' type will copy the member / enumeration data.
1661 char *list
= type
->fieldlist
.list
;
1662 int len
= (ptr
+ type
->generic
.len
+ 2) - list
;
1664 if ( ((union codeview_fieldtype
*)list
)->generic
.id
== LF_ENUMERATE
)
1665 retv
= DEBUG_AddCVType_EnumFieldList( curr_type
, list
, len
);
1667 retv
= DEBUG_AddCVType_StructFieldList( curr_type
, list
, len
);
1674 int structlen
, slen
= numeric_leaf( &structlen
, &type
->structure
.structlen
);
1675 unsigned char *name
= (unsigned char *)&type
->structure
.structlen
+ slen
;
1677 retv
= DEBUG_AddCVType_Struct( curr_type
, terminate_string( name
),
1678 structlen
, type
->structure
.fieldlist
);
1681 case LF_STRUCTURE_32
:
1684 int structlen
, slen
= numeric_leaf( &structlen
, &type
->structure32
.structlen
);
1685 unsigned char *name
= (unsigned char *)&type
->structure32
.structlen
+ slen
;
1687 retv
= DEBUG_AddCVType_Struct( curr_type
, terminate_string( name
),
1688 structlen
, type
->structure32
.fieldlist
);
1694 int un_len
, ulen
= numeric_leaf( &un_len
, &type
->t_union
.un_len
);
1695 unsigned char *name
= (unsigned char *)&type
->t_union
.un_len
+ ulen
;
1697 retv
= DEBUG_AddCVType_Struct( curr_type
, terminate_string( name
),
1698 un_len
, type
->t_union
.fieldlist
);
1703 int un_len
, ulen
= numeric_leaf( &un_len
, &type
->t_union32
.un_len
);
1704 unsigned char *name
= (unsigned char *)&type
->t_union32
.un_len
+ ulen
;
1706 retv
= DEBUG_AddCVType_Struct( curr_type
, terminate_string( name
),
1707 un_len
, type
->t_union32
.fieldlist
);
1712 retv
= DEBUG_AddCVType_Enum( curr_type
, terminate_string( type
->enumeration
.name
),
1713 type
->enumeration
.field
);
1716 retv
= DEBUG_AddCVType_Enum( curr_type
, terminate_string( type
->enumeration32
.name
),
1717 type
->enumeration32
.field
);
1728 ptr
+= type
->generic
.len
+ 2;
1735 /*========================================================================
1736 * Process CodeView line number information.
1753 struct codeview_linetab_hdr
1760 unsigned short * linetab
;
1761 unsigned int * offtab
;
1764 static struct codeview_linetab_hdr
*
1765 DEBUG_SnarfLinetab(char * linetab
,
1769 char filename
[PATH_MAX
];
1770 unsigned int * filetab
;
1774 struct codeview_linetab_hdr
* lt_hdr
;
1775 unsigned int * lt_ptr
;
1779 union any_size pnt2
;
1780 struct startend
* start
;
1784 * Now get the important bits.
1790 filetab
= (unsigned int *) pnt
.c
;
1793 * Now count up the number of segments in the file.
1796 for(i
=0; i
<nfile
; i
++)
1798 pnt2
.c
= linetab
+ filetab
[i
];
1803 * Next allocate the header we will be returning.
1804 * There is one header for each segment, so that we can reach in
1805 * and pull bits as required.
1807 lt_hdr
= (struct codeview_linetab_hdr
*)
1808 DBG_alloc((nseg
+ 1) * sizeof(*lt_hdr
));
1809 if( lt_hdr
== NULL
)
1814 memset(lt_hdr
, 0, sizeof(*lt_hdr
) * (nseg
+1));
1817 * Now fill the header we will be returning, one for each segment.
1818 * Note that this will basically just contain pointers into the existing
1819 * line table, and we do not actually copy any additional information
1820 * or allocate any additional memory.
1824 for(i
=0; i
<nfile
; i
++)
1827 * Get the pointer into the segment information.
1829 pnt2
.c
= linetab
+ filetab
[i
];
1830 file_segcount
= *pnt2
.s
;
1833 lt_ptr
= (unsigned int *) pnt2
.c
;
1834 start
= (struct startend
*) (lt_ptr
+ file_segcount
);
1837 * Now snarf the filename for all of the segments for this file.
1839 fn
= (unsigned char *) (start
+ file_segcount
);
1840 memset(filename
, 0, sizeof(filename
));
1841 memcpy(filename
, fn
+ 1, *fn
);
1842 fn
= DBG_strdup(filename
);
1844 for(k
= 0; k
< file_segcount
; k
++, this_seg
++)
1846 pnt2
.c
= linetab
+ lt_ptr
[k
];
1847 lt_hdr
[this_seg
].start
= start
[k
].start
;
1848 lt_hdr
[this_seg
].end
= start
[k
].end
;
1849 lt_hdr
[this_seg
].sourcefile
= fn
;
1850 lt_hdr
[this_seg
].segno
= *pnt2
.s
++;
1851 lt_hdr
[this_seg
].nline
= *pnt2
.s
++;
1852 lt_hdr
[this_seg
].offtab
= pnt2
.ui
;
1853 lt_hdr
[this_seg
].linetab
= (unsigned short *)
1854 (pnt2
.ui
+ lt_hdr
[this_seg
].nline
);
1865 /*========================================================================
1866 * Process CodeView symbol information.
1869 union codeview_symbol
1881 unsigned int offset
;
1883 unsigned short symtype
;
1884 unsigned char namelen
;
1885 unsigned char name
[1];
1892 unsigned int symtype
;
1893 unsigned int offset
;
1895 unsigned char namelen
;
1896 unsigned char name
[1];
1903 unsigned int pparent
;
1906 unsigned int offset
;
1907 unsigned short segment
;
1908 unsigned short thunk_len
;
1909 unsigned char thtype
;
1910 unsigned char namelen
;
1911 unsigned char name
[1];
1918 unsigned int pparent
;
1921 unsigned int proc_len
;
1922 unsigned int debug_start
;
1923 unsigned int debug_end
;
1924 unsigned int offset
;
1925 unsigned short segment
;
1926 unsigned short proctype
;
1927 unsigned char flags
;
1928 unsigned char namelen
;
1929 unsigned char name
[1];
1936 unsigned int pparent
;
1939 unsigned int proc_len
;
1940 unsigned int debug_start
;
1941 unsigned int debug_end
;
1942 unsigned int proctype
;
1943 unsigned int offset
;
1944 unsigned short segment
;
1945 unsigned char flags
;
1946 unsigned char namelen
;
1947 unsigned char name
[1];
1952 short int len
; /* Total length of this entry */
1953 short int id
; /* Always S_BPREL32 */
1954 unsigned int offset
; /* Stack offset relative to BP */
1955 unsigned short symtype
;
1956 unsigned char namelen
;
1957 unsigned char name
[1];
1962 short int len
; /* Total length of this entry */
1963 short int id
; /* Always S_BPREL32 */
1964 unsigned int offset
; /* Stack offset relative to BP */
1965 unsigned int symtype
;
1966 unsigned char namelen
;
1967 unsigned char name
[1];
1972 #define S_COMPILE 0x0001
1973 #define S_REGISTER 0x0002
1974 #define S_CONSTANT 0x0003
1975 #define S_UDT 0x0004
1976 #define S_SSEARCH 0x0005
1977 #define S_END 0x0006
1978 #define S_SKIP 0x0007
1979 #define S_CVRESERVE 0x0008
1980 #define S_OBJNAME 0x0009
1981 #define S_ENDARG 0x000a
1982 #define S_COBOLUDT 0x000b
1983 #define S_MANYREG 0x000c
1984 #define S_RETURN 0x000d
1985 #define S_ENTRYTHIS 0x000e
1987 #define S_BPREL 0x0200
1988 #define S_LDATA 0x0201
1989 #define S_GDATA 0x0202
1990 #define S_PUB 0x0203
1991 #define S_LPROC 0x0204
1992 #define S_GPROC 0x0205
1993 #define S_THUNK 0x0206
1994 #define S_BLOCK 0x0207
1995 #define S_WITH 0x0208
1996 #define S_LABEL 0x0209
1997 #define S_CEXMODEL 0x020a
1998 #define S_VFTPATH 0x020b
1999 #define S_REGREL 0x020c
2000 #define S_LTHREAD 0x020d
2001 #define S_GTHREAD 0x020e
2003 #define S_PROCREF 0x0400
2004 #define S_DATAREF 0x0401
2005 #define S_ALIGN 0x0402
2006 #define S_LPROCREF 0x0403
2008 #define S_REGISTER_32 0x1001 /* Variants with new 32-bit type indices */
2009 #define S_CONSTANT_32 0x1002
2010 #define S_UDT_32 0x1003
2011 #define S_COBOLUDT_32 0x1004
2012 #define S_MANYREG_32 0x1005
2014 #define S_BPREL_32 0x1006
2015 #define S_LDATA_32 0x1007
2016 #define S_GDATA_32 0x1008
2017 #define S_PUB_32 0x1009
2018 #define S_LPROC_32 0x100a
2019 #define S_GPROC_32 0x100b
2020 #define S_VFTTABLE_32 0x100c
2021 #define S_REGREL_32 0x100d
2022 #define S_LTHREAD_32 0x100e
2023 #define S_GTHREAD_32 0x100f
2028 DEBUG_MapCVOffset( DBG_MODULE
*module
, unsigned int offset
)
2030 int nomap
= module
->msc_info
->nomap
;
2031 OMAP_DATA
*omapp
= module
->msc_info
->omapp
;
2034 if ( !nomap
|| !omapp
)
2037 /* FIXME: use binary search */
2038 for ( i
= 0; i
< nomap
-1; i
++ )
2039 if ( omapp
[i
].from
<= offset
&& omapp
[i
+1].from
> offset
)
2040 return !omapp
[i
].to
? 0 : omapp
[i
].to
+ (offset
- omapp
[i
].from
);
2045 static struct name_hash
*
2046 DEBUG_AddCVSymbol( DBG_MODULE
*module
, char *name
, int namelen
,
2047 int type
, unsigned int seg
, unsigned int offset
,
2048 int size
, int cookie
, int flags
,
2049 struct codeview_linetab_hdr
*linetab
)
2051 int nsect
= module
->msc_info
->nsect
;
2052 PIMAGE_SECTION_HEADER sectp
= module
->msc_info
->sectp
;
2054 struct name_hash
*symbol
;
2055 char symname
[PATH_MAX
];
2059 * Some sanity checks
2062 if ( !name
|| !namelen
)
2065 if ( !seg
|| seg
> nsect
)
2069 * Convert type, address, and symbol name
2071 value
.type
= type
? DEBUG_GetCVType( type
) : NULL
;
2072 value
.cookie
= cookie
;
2075 value
.addr
.off
= (unsigned int) module
->load_addr
+
2076 DEBUG_MapCVOffset( module
, sectp
[seg
-1].VirtualAddress
+ offset
);
2078 memcpy( symname
, name
, namelen
);
2079 symname
[namelen
] = '\0';
2083 * Check whether we have line number information
2087 for ( ; linetab
->linetab
; linetab
++ )
2088 if ( linetab
->segno
== seg
2089 && linetab
->start
<= offset
2090 && linetab
->end
> offset
)
2093 if ( !linetab
->linetab
)
2099 * Create Wine symbol record
2101 symbol
= DEBUG_AddSymbol( symname
, &value
,
2102 linetab
? linetab
->sourcefile
: NULL
, flags
);
2105 DEBUG_SetSymbolSize( symbol
, size
);
2109 * Add line numbers if found
2114 for ( i
= 0; i
< linetab
->nline
; i
++ )
2115 if ( linetab
->offtab
[i
] >= offset
2116 && linetab
->offtab
[i
] < offset
+ size
)
2118 DEBUG_AddLineNumber( symbol
, linetab
->linetab
[i
],
2119 linetab
->offtab
[i
] - offset
);
2126 static struct wine_locals
*
2127 DEBUG_AddCVLocal( struct name_hash
*func
, char *name
, int namelen
,
2128 int type
, int offset
)
2130 struct wine_locals
*local
;
2131 char symname
[PATH_MAX
];
2133 memcpy( symname
, name
, namelen
);
2134 symname
[namelen
] = '\0';
2136 local
= DEBUG_AddLocal( func
, 0, offset
, 0, 0, symname
);
2137 DEBUG_SetLocalSymbolType( local
, DEBUG_GetCVType( type
) );
2143 DEBUG_SnarfCodeView( DBG_MODULE
*module
, LPBYTE root
, int offset
, int size
,
2144 struct codeview_linetab_hdr
*linetab
)
2146 struct name_hash
*curr_func
= NULL
;
2151 * Loop over the different types of records and whenever we
2152 * find something we are interested in, record it and move on.
2154 for ( i
= offset
; i
< size
; i
+= length
)
2156 union codeview_symbol
*sym
= (union codeview_symbol
*)(root
+ i
);
2157 length
= sym
->generic
.len
+ 2;
2159 switch ( sym
->generic
.id
)
2162 * Global and local data symbols. We don't associate these
2163 * with any given source file.
2168 DEBUG_AddCVSymbol( module
, sym
->data
.name
, sym
->data
.namelen
,
2169 sym
->data
.symtype
, sym
->data
.seg
,
2170 sym
->data
.offset
, 0,
2171 DV_TARGET
, SYM_WIN32
| SYM_DATA
, NULL
);
2176 DEBUG_AddCVSymbol( module
, sym
->data32
.name
, sym
->data32
.namelen
,
2177 sym
->data32
.symtype
, sym
->data32
.seg
,
2178 sym
->data32
.offset
, 0,
2179 DV_TARGET
, SYM_WIN32
| SYM_DATA
, NULL
);
2183 * Sort of like a global function, but it just points
2184 * to a thunk, which is a stupid name for what amounts to
2185 * a PLT slot in the normal jargon that everyone else uses.
2188 DEBUG_AddCVSymbol( module
, sym
->thunk
.name
, sym
->thunk
.namelen
,
2189 0, sym
->thunk
.segment
,
2190 sym
->thunk
.offset
, sym
->thunk
.thunk_len
,
2191 DV_TARGET
, SYM_WIN32
| SYM_FUNC
, NULL
);
2195 * Global and static functions.
2199 DEBUG_Normalize( curr_func
);
2201 curr_func
= DEBUG_AddCVSymbol( module
, sym
->proc
.name
, sym
->proc
.namelen
,
2202 sym
->proc
.proctype
, sym
->proc
.segment
,
2203 sym
->proc
.offset
, sym
->proc
.proc_len
,
2204 DV_TARGET
, SYM_WIN32
| SYM_FUNC
, linetab
);
2206 DEBUG_SetSymbolBPOff( curr_func
, sym
->proc
.debug_start
);
2210 DEBUG_Normalize( curr_func
);
2212 curr_func
= DEBUG_AddCVSymbol( module
, sym
->proc32
.name
, sym
->proc32
.namelen
,
2213 sym
->proc32
.proctype
, sym
->proc32
.segment
,
2214 sym
->proc32
.offset
, sym
->proc32
.proc_len
,
2215 DV_TARGET
, SYM_WIN32
| SYM_FUNC
, linetab
);
2217 DEBUG_SetSymbolBPOff( curr_func
, sym
->proc32
.debug_start
);
2222 * Function parameters and stack variables.
2225 DEBUG_AddCVLocal( curr_func
, sym
->stack
.name
, sym
->stack
.namelen
,
2226 sym
->stack
.symtype
, sym
->stack
.offset
);
2229 DEBUG_AddCVLocal( curr_func
, sym
->stack32
.name
, sym
->stack32
.namelen
,
2230 sym
->stack32
.symtype
, sym
->stack32
.offset
);
2235 * These are special, in that they are always followed by an
2236 * additional length-prefixed string which is *not* included
2237 * into the symbol length count. We need to skip it.
2243 LPBYTE name
= (LPBYTE
)sym
+ length
;
2244 length
+= (*name
+ 1 + 3) & ~3;
2250 DEBUG_Normalize( curr_func
);
2252 if ( linetab
) DBG_free(linetab
);
2258 /*========================================================================
2263 typedef struct _PDB_FILE
2268 } PDB_FILE
, *PPDB_FILE
;
2270 typedef struct _PDB_HEADER
2278 WORD toc_block
[ 1 ];
2280 } PDB_HEADER
, *PPDB_HEADER
;
2282 typedef struct _PDB_TOC
2287 } PDB_TOC
, *PPDB_TOC
;
2289 typedef struct _PDB_ROOT
2292 DWORD TimeDateStamp
;
2297 } PDB_ROOT
, *PPDB_ROOT
;
2299 typedef struct _PDB_TYPES_OLD
2308 } PDB_TYPES_OLD
, *PPDB_TYPES_OLD
;
2310 typedef struct _PDB_TYPES
2323 DWORD search_offset
;
2325 DWORD unknown_offset
;
2328 } PDB_TYPES
, *PPDB_TYPES
;
2330 typedef struct _PDB_SYMBOL_RANGE
2336 DWORD characteristics
;
2340 } PDB_SYMBOL_RANGE
, *PPDB_SYMBOL_RANGE
;
2342 typedef struct _PDB_SYMBOL_RANGE_EX
2348 DWORD characteristics
;
2354 } PDB_SYMBOL_RANGE_EX
, *PPDB_SYMBOL_RANGE_EX
;
2356 typedef struct _PDB_SYMBOL_FILE
2359 PDB_SYMBOL_RANGE range
;
2369 } PDB_SYMBOL_FILE
, *PPDB_SYMBOL_FILE
;
2371 typedef struct _PDB_SYMBOL_FILE_EX
2374 PDB_SYMBOL_RANGE_EX range
;
2382 DWORD reserved
[ 2 ];
2385 } PDB_SYMBOL_FILE_EX
, *PPDB_SYMBOL_FILE_EX
;
2387 typedef struct _PDB_SYMBOL_SOURCE
2393 } PDB_SYMBOL_SOURCE
, *PPDB_SYMBOL_SOURCE
;
2395 typedef struct _PDB_SYMBOL_IMPORT
2399 DWORD TimeDateStamp
;
2403 } PDB_SYMBOL_IMPORT
, *PPDB_SYMBOL_IMPORT
;
2405 typedef struct _PDB_SYMBOLS_OLD
2414 DWORD srcmodule_size
;
2416 } PDB_SYMBOLS_OLD
, *PPDB_SYMBOLS_OLD
;
2418 typedef struct _PDB_SYMBOLS
2429 DWORD srcmodule_size
;
2430 DWORD pdbimport_size
;
2433 } PDB_SYMBOLS
, *PPDB_SYMBOLS
;
2437 static void *pdb_read( LPBYTE image
, WORD
*block_list
, int size
)
2439 PPDB_HEADER pdb
= (PPDB_HEADER
)image
;
2443 if ( !size
) return NULL
;
2445 nBlocks
= (size
+ pdb
->blocksize
-1) / pdb
->blocksize
;
2446 buffer
= DBG_alloc( nBlocks
* pdb
->blocksize
);
2448 for ( i
= 0; i
< nBlocks
; i
++ )
2449 memcpy( buffer
+ i
*pdb
->blocksize
,
2450 image
+ block_list
[i
]*pdb
->blocksize
, pdb
->blocksize
);
2455 static void *pdb_read_file( LPBYTE image
, PPDB_TOC toc
, DWORD fileNr
)
2457 PPDB_HEADER pdb
= (PPDB_HEADER
)image
;
2461 if ( !toc
|| fileNr
>= toc
->nFiles
)
2464 block_list
= (WORD
*) &toc
->file
[ toc
->nFiles
];
2465 for ( i
= 0; i
< fileNr
; i
++ )
2466 block_list
+= (toc
->file
[i
].size
+ pdb
->blocksize
-1) / pdb
->blocksize
;
2468 return pdb_read( image
, block_list
, toc
->file
[fileNr
].size
);
2471 static void pdb_free( void *buffer
)
2476 static void pdb_convert_types_header( PDB_TYPES
*types
, char *image
)
2478 memset( types
, 0, sizeof(PDB_TYPES
) );
2479 if ( !image
) return;
2481 if ( *(DWORD
*)image
< 19960000 ) /* FIXME: correct version? */
2483 /* Old version of the types record header */
2484 PDB_TYPES_OLD
*old
= (PDB_TYPES_OLD
*)image
;
2485 types
->version
= old
->version
;
2486 types
->type_offset
= sizeof(PDB_TYPES_OLD
);
2487 types
->type_size
= old
->type_size
;
2488 types
->first_index
= old
->first_index
;
2489 types
->last_index
= old
->last_index
;
2490 types
->file
= old
->file
;
2494 /* New version of the types record header */
2495 *types
= *(PDB_TYPES
*)image
;
2499 static void pdb_convert_symbols_header( PDB_SYMBOLS
*symbols
,
2500 int *header_size
, char *image
)
2502 memset( symbols
, 0, sizeof(PDB_SYMBOLS
) );
2503 if ( !image
) return;
2505 if ( *(DWORD
*)image
!= 0xffffffff )
2507 /* Old version of the symbols record header */
2508 PDB_SYMBOLS_OLD
*old
= (PDB_SYMBOLS_OLD
*)image
;
2509 symbols
->version
= 0;
2510 symbols
->module_size
= old
->module_size
;
2511 symbols
->offset_size
= old
->offset_size
;
2512 symbols
->hash_size
= old
->hash_size
;
2513 symbols
->srcmodule_size
= old
->srcmodule_size
;
2514 symbols
->pdbimport_size
= 0;
2515 symbols
->hash1_file
= old
->hash1_file
;
2516 symbols
->hash2_file
= old
->hash2_file
;
2517 symbols
->gsym_file
= old
->gsym_file
;
2519 *header_size
= sizeof(PDB_SYMBOLS_OLD
);
2523 /* New version of the symbols record header */
2524 *symbols
= *(PDB_SYMBOLS
*)image
;
2526 *header_size
= sizeof(PDB_SYMBOLS
);
2530 static enum DbgInfoLoad
DEBUG_ProcessPDBFile( DBG_MODULE
*module
,
2531 const char *filename
, DWORD timestamp
)
2533 enum DbgInfoLoad dil
= DIL_ERROR
;
2536 PDB_HEADER
*pdb
= NULL
;
2537 PDB_TOC
*toc
= NULL
;
2538 PDB_ROOT
*root
= NULL
;
2539 char *types_image
= NULL
;
2540 char *symbols_image
= NULL
;
2542 PDB_SYMBOLS symbols
;
2543 int header_size
= 0;
2544 char *modimage
, *file
;
2546 DEBUG_Printf( DBG_CHN_TRACE
, "Processing PDB file %s\n", filename
);
2549 * Open and map() .PDB file
2551 image
= DEBUG_MapDebugInfoFile( filename
, 0, 0, &hFile
, &hMap
);
2554 DEBUG_Printf( DBG_CHN_ERR
, "-Unable to peruse .PDB file %s\n", filename
);
2559 * Read in TOC and well-known files
2562 pdb
= (PPDB_HEADER
)image
;
2563 toc
= pdb_read( image
, pdb
->toc_block
, pdb
->toc
.size
);
2564 root
= pdb_read_file( image
, toc
, 1 );
2565 types_image
= pdb_read_file( image
, toc
, 2 );
2566 symbols_image
= pdb_read_file( image
, toc
, 3 );
2568 pdb_convert_types_header( &types
, types_image
);
2569 pdb_convert_symbols_header( &symbols
, &header_size
, symbols_image
);
2572 * Check for unknown versions
2575 switch ( root
->version
)
2577 case 19950623: /* VC 4.0 */
2579 case 19960307: /* VC 5.0 */
2580 case 19970604: /* VC 6.0 */
2583 DEBUG_Printf( DBG_CHN_ERR
, "-Unknown root block version %ld\n", root
->version
);
2586 switch ( types
.version
)
2588 case 19950410: /* VC 4.0 */
2590 case 19961031: /* VC 5.0 / 6.0 */
2593 DEBUG_Printf( DBG_CHN_ERR
, "-Unknown type info version %ld\n", types
.version
);
2596 switch ( symbols
.version
)
2598 case 0: /* VC 4.0 */
2599 case 19960307: /* VC 5.0 */
2600 case 19970606: /* VC 6.0 */
2603 DEBUG_Printf( DBG_CHN_ERR
, "-Unknown symbol info version %ld\n", symbols
.version
);
2608 * Check .PDB time stamp
2611 if ( root
->TimeDateStamp
!= timestamp
)
2613 DEBUG_Printf( DBG_CHN_ERR
, "-Wrong time stamp of .PDB file %s (0x%08lx, 0x%08lx)\n",
2614 filename
, root
->TimeDateStamp
, timestamp
);
2621 DEBUG_ParseTypeTable( types_image
+ types
.type_offset
, types
.type_size
);
2624 * Read type-server .PDB imports
2627 if ( symbols
.pdbimport_size
)
2630 DEBUG_Printf(DBG_CHN_ERR
, "-Type server .PDB imports ignored!\n" );
2634 * Read global symbol table
2637 modimage
= pdb_read_file( image
, toc
, symbols
.gsym_file
);
2640 DEBUG_SnarfCodeView( module
, modimage
, 0,
2641 toc
->file
[symbols
.gsym_file
].size
, NULL
);
2642 pdb_free( modimage
);
2646 * Read per-module symbol / linenumber tables
2649 file
= symbols_image
+ header_size
;
2650 while ( file
- symbols_image
< header_size
+ symbols
.module_size
)
2652 int file_nr
, file_index
, symbol_size
, lineno_size
;
2655 if ( symbols
.version
< 19970000 )
2657 PDB_SYMBOL_FILE
*sym_file
= (PDB_SYMBOL_FILE
*) file
;
2658 file_nr
= sym_file
->file
;
2659 file_name
= sym_file
->filename
;
2660 file_index
= sym_file
->range
.index
;
2661 symbol_size
= sym_file
->symbol_size
;
2662 lineno_size
= sym_file
->lineno_size
;
2666 PDB_SYMBOL_FILE_EX
*sym_file
= (PDB_SYMBOL_FILE_EX
*) file
;
2667 file_nr
= sym_file
->file
;
2668 file_name
= sym_file
->filename
;
2669 file_index
= sym_file
->range
.index
;
2670 symbol_size
= sym_file
->symbol_size
;
2671 lineno_size
= sym_file
->lineno_size
;
2674 modimage
= pdb_read_file( image
, toc
, file_nr
);
2677 struct codeview_linetab_hdr
*linetab
= NULL
;
2680 linetab
= DEBUG_SnarfLinetab( modimage
+ symbol_size
, lineno_size
);
2683 DEBUG_SnarfCodeView( module
, modimage
, sizeof(DWORD
),
2684 symbol_size
, linetab
);
2686 pdb_free( modimage
);
2689 file_name
+= strlen(file_name
) + 1;
2690 file
= (char *)( (DWORD
)(file_name
+ strlen(file_name
) + 1 + 3) & ~3 );
2701 DEBUG_ClearTypeTable();
2703 if ( symbols_image
) pdb_free( symbols_image
);
2704 if ( types_image
) pdb_free( types_image
);
2705 if ( root
) pdb_free( root
);
2706 if ( toc
) pdb_free( toc
);
2708 DEBUG_UnmapDebugInfoFile(hFile
, hMap
, image
);
2716 /*========================================================================
2717 * Process CodeView debug information.
2720 #define CODEVIEW_NB09_SIG ( 'N' | ('B' << 8) | ('0' << 16) | ('9' << 24) )
2721 #define CODEVIEW_NB10_SIG ( 'N' | ('B' << 8) | ('1' << 16) | ('0' << 24) )
2722 #define CODEVIEW_NB11_SIG ( 'N' | ('B' << 8) | ('1' << 16) | ('1' << 24) )
2724 typedef struct _CODEVIEW_HEADER
2729 } CODEVIEW_HEADER
, *PCODEVIEW_HEADER
;
2731 typedef struct _CODEVIEW_PDB_DATA
2737 } CODEVIEW_PDB_DATA
, *PCODEVIEW_PDB_DATA
;
2739 typedef struct _CV_DIRECTORY_HEADER
2747 } CV_DIRECTORY_HEADER
, *PCV_DIRECTORY_HEADER
;
2749 typedef struct _CV_DIRECTORY_ENTRY
2756 } CV_DIRECTORY_ENTRY
, *PCV_DIRECTORY_ENTRY
;
2759 #define sstAlignSym 0x125
2760 #define sstSrcModule 0x127
2763 static enum DbgInfoLoad
DEBUG_ProcessCodeView( DBG_MODULE
*module
, LPBYTE root
)
2765 PCODEVIEW_HEADER cv
= (PCODEVIEW_HEADER
)root
;
2766 enum DbgInfoLoad dil
= DIL_ERROR
;
2768 switch ( cv
->dwSignature
)
2770 case CODEVIEW_NB09_SIG
:
2771 case CODEVIEW_NB11_SIG
:
2773 PCV_DIRECTORY_HEADER hdr
= (PCV_DIRECTORY_HEADER
)(root
+ cv
->lfoDirectory
);
2774 PCV_DIRECTORY_ENTRY ent
, prev
, next
;
2777 ent
= (PCV_DIRECTORY_ENTRY
)((LPBYTE
)hdr
+ hdr
->cbDirHeader
);
2778 for ( i
= 0; i
< hdr
->cDir
; i
++, ent
= next
)
2780 next
= (i
== hdr
->cDir
-1)? NULL
:
2781 (PCV_DIRECTORY_ENTRY
)((LPBYTE
)ent
+ hdr
->cbDirEntry
);
2782 prev
= (i
== 0)? NULL
:
2783 (PCV_DIRECTORY_ENTRY
)((LPBYTE
)ent
- hdr
->cbDirEntry
);
2785 if ( ent
->subsection
== sstAlignSym
)
2788 * Check the next and previous entry. If either is a
2789 * sstSrcModule, it contains the line number info for
2792 * FIXME: This is not a general solution!
2794 struct codeview_linetab_hdr
*linetab
= NULL
;
2796 if ( next
&& next
->iMod
== ent
->iMod
2797 && next
->subsection
== sstSrcModule
)
2798 linetab
= DEBUG_SnarfLinetab( root
+ next
->lfo
, next
->cb
);
2800 if ( prev
&& prev
->iMod
== ent
->iMod
2801 && prev
->subsection
== sstSrcModule
)
2802 linetab
= DEBUG_SnarfLinetab( root
+ prev
->lfo
, prev
->cb
);
2805 DEBUG_SnarfCodeView( module
, root
+ ent
->lfo
, sizeof(DWORD
),
2814 case CODEVIEW_NB10_SIG
:
2816 PCODEVIEW_PDB_DATA pdb
= (PCODEVIEW_PDB_DATA
)(cv
+ 1);
2818 dil
= DEBUG_ProcessPDBFile( module
, pdb
->name
, pdb
->timestamp
);
2823 DEBUG_Printf( DBG_CHN_ERR
, "Unknown CODEVIEW signature %08lX in module %s\n",
2824 cv
->dwSignature
, module
->module_name
);
2832 /*========================================================================
2833 * Process debug directory.
2835 static enum DbgInfoLoad
DEBUG_ProcessDebugDirectory( DBG_MODULE
*module
,
2837 PIMAGE_DEBUG_DIRECTORY dbg
,
2840 enum DbgInfoLoad dil
= DIL_ERROR
;
2843 /* First, watch out for OMAP data */
2844 for ( i
= 0; i
< nDbg
; i
++ )
2845 if ( dbg
[i
].Type
== IMAGE_DEBUG_TYPE_OMAP_FROM_SRC
)
2847 module
->msc_info
->nomap
= dbg
[i
].SizeOfData
/ sizeof(OMAP_DATA
);
2848 module
->msc_info
->omapp
= (OMAP_DATA
*)(file_map
+ dbg
[i
].PointerToRawData
);
2853 /* Now, try to parse CodeView debug info */
2854 for ( i
= 0; dil
!= DIL_LOADED
&& i
< nDbg
; i
++ )
2855 if ( dbg
[i
].Type
== IMAGE_DEBUG_TYPE_CODEVIEW
)
2856 dil
= DEBUG_ProcessCodeView( module
, file_map
+ dbg
[i
].PointerToRawData
);
2859 /* If not found, try to parse COFF debug info */
2860 for ( i
= 0; dil
!= DIL_LOADED
&& i
< nDbg
; i
++ )
2861 if ( dbg
[i
].Type
== IMAGE_DEBUG_TYPE_COFF
)
2862 dil
= DEBUG_ProcessCoff( module
, file_map
+ dbg
[i
].PointerToRawData
);
2865 /* FIXME: this should be supported... this is the debug information for
2866 * functions compiled without a frame pointer (FPO = frame pointer omission)
2867 * the associated data helps finding out the relevant information
2869 for ( i
= 0; i
< nDbg
; i
++ )
2870 if ( dbg
[i
].Type
== IMAGE_DEBUG_TYPE_FPO
)
2871 DEBUG_Printf(DBG_CHN_MESG
, "This guy has FPO information\n");
2874 #define FRAME_TRAP 1
2877 typedef struct _FPO_DATA
{
2878 DWORD ulOffStart
; /* offset 1st byte of function code */
2879 DWORD cbProcSize
; /* # bytes in function */
2880 DWORD cdwLocals
; /* # bytes in locals/4 */
2881 WORD cdwParams
; /* # bytes in params/4 */
2883 WORD cbProlog
: 8; /* # bytes in prolog */
2884 WORD cbRegs
: 3; /* # regs saved */
2885 WORD fHasSEH
: 1; /* TRUE if SEH in func */
2886 WORD fUseBP
: 1; /* TRUE if EBP has been allocated */
2887 WORD reserved
: 1; /* reserved for future use */
2888 WORD cbFrame
: 2; /* frame type */
2896 /*========================================================================
2899 static enum DbgInfoLoad
DEBUG_ProcessDBGFile( DBG_MODULE
*module
,
2900 const char *filename
, DWORD timestamp
)
2902 enum DbgInfoLoad dil
= DIL_ERROR
;
2903 HANDLE hFile
= INVALID_HANDLE_VALUE
, hMap
= 0;
2904 LPBYTE file_map
= NULL
;
2905 PIMAGE_SEPARATE_DEBUG_HEADER hdr
;
2906 PIMAGE_DEBUG_DIRECTORY dbg
;
2910 DEBUG_Printf( DBG_CHN_TRACE
, "Processing DBG file %s\n", filename
);
2912 file_map
= DEBUG_MapDebugInfoFile( filename
, 0, 0, &hFile
, &hMap
);
2915 DEBUG_Printf( DBG_CHN_ERR
, "-Unable to peruse .DBG file %s\n", filename
);
2919 hdr
= (PIMAGE_SEPARATE_DEBUG_HEADER
) file_map
;
2921 if ( hdr
->TimeDateStamp
!= timestamp
)
2923 DEBUG_Printf( DBG_CHN_ERR
, "Warning - %s has incorrect internal timestamp\n",
2926 * Well, sometimes this happens to DBG files which ARE REALLY the right .DBG
2927 * files but nonetheless this check fails. Anyway, WINDBG (debugger for
2928 * Windows by Microsoft) loads debug symbols which have incorrect timestamps.
2933 dbg
= (PIMAGE_DEBUG_DIRECTORY
) ( file_map
+ sizeof(*hdr
)
2934 + hdr
->NumberOfSections
* sizeof(IMAGE_SECTION_HEADER
)
2935 + hdr
->ExportedNamesSize
);
2937 nDbg
= hdr
->DebugDirectorySize
/ sizeof(*dbg
);
2939 dil
= DEBUG_ProcessDebugDirectory( module
, file_map
, dbg
, nDbg
);
2943 DEBUG_UnmapDebugInfoFile( hFile
, hMap
, file_map
);
2948 /*========================================================================
2949 * Process MSC debug information in PE file.
2951 enum DbgInfoLoad
DEBUG_RegisterMSCDebugInfo( DBG_MODULE
*module
, HANDLE hFile
,
2952 void *_nth
, unsigned long nth_ofs
)
2954 enum DbgInfoLoad dil
= DIL_ERROR
;
2955 PIMAGE_NT_HEADERS nth
= (PIMAGE_NT_HEADERS
)_nth
;
2956 PIMAGE_DATA_DIRECTORY dir
= nth
->OptionalHeader
.DataDirectory
+ IMAGE_DIRECTORY_ENTRY_DEBUG
;
2957 PIMAGE_DEBUG_DIRECTORY dbg
= NULL
;
2959 MSC_DBG_INFO extra_info
= { 0, NULL
, 0, NULL
};
2961 LPBYTE file_map
= NULL
;
2964 /* Read in section data */
2966 module
->msc_info
= &extra_info
;
2967 extra_info
.nsect
= nth
->FileHeader
.NumberOfSections
;
2968 extra_info
.sectp
= DBG_alloc( extra_info
.nsect
* sizeof(IMAGE_SECTION_HEADER
) );
2969 if ( !extra_info
.sectp
)
2972 if ( !DEBUG_READ_MEM_VERBOSE( (char *)module
->load_addr
+
2973 nth_ofs
+ OFFSET_OF(IMAGE_NT_HEADERS
, OptionalHeader
) +
2974 nth
->FileHeader
.SizeOfOptionalHeader
,
2976 extra_info
.nsect
* sizeof(IMAGE_SECTION_HEADER
) ) )
2979 /* Read in debug directory */
2981 nDbg
= dir
->Size
/ sizeof(IMAGE_DEBUG_DIRECTORY
);
2985 dbg
= (PIMAGE_DEBUG_DIRECTORY
) DBG_alloc( nDbg
* sizeof(IMAGE_DEBUG_DIRECTORY
) );
2989 if ( !DEBUG_READ_MEM_VERBOSE( (char *)module
->load_addr
+ dir
->VirtualAddress
,
2990 dbg
, nDbg
* sizeof(IMAGE_DEBUG_DIRECTORY
) ) )
2994 /* Map in PE file */
2995 file_map
= DEBUG_MapDebugInfoFile( NULL
, 0, 0, &hFile
, &hMap
);
3000 /* Parse debug directory */
3002 if ( nth
->FileHeader
.Characteristics
& IMAGE_FILE_DEBUG_STRIPPED
)
3004 /* Debug info is stripped to .DBG file */
3006 PIMAGE_DEBUG_MISC misc
= (PIMAGE_DEBUG_MISC
)(file_map
+ dbg
->PointerToRawData
);
3008 if ( nDbg
!= 1 || dbg
->Type
!= IMAGE_DEBUG_TYPE_MISC
3009 || misc
->DataType
!= IMAGE_DEBUG_MISC_EXENAME
)
3011 DEBUG_Printf( DBG_CHN_ERR
, "-Debug info stripped, but no .DBG file in module %s\n",
3012 module
->module_name
);
3016 dil
= DEBUG_ProcessDBGFile( module
, misc
->Data
, nth
->FileHeader
.TimeDateStamp
);
3020 /* Debug info is embedded into PE module */
3022 dil
= DEBUG_ProcessDebugDirectory( module
, file_map
, dbg
, nDbg
);
3027 module
->msc_info
= NULL
;
3029 DEBUG_UnmapDebugInfoFile( 0, hMap
, file_map
);
3030 if ( extra_info
.sectp
) DBG_free( extra_info
.sectp
);
3031 if ( dbg
) DBG_free( dbg
);
3036 /*========================================================================
3037 * look for stabs information in PE header (it's how mingw compiler provides its
3038 * debugging information), and also wine PE <-> ELF linking through .wsolnk sections
3040 enum DbgInfoLoad
DEBUG_RegisterStabsDebugInfo(DBG_MODULE
* module
, HANDLE hFile
,
3041 void* _nth
, unsigned long nth_ofs
)
3043 IMAGE_SECTION_HEADER pe_seg
;
3044 unsigned long pe_seg_ofs
;
3045 int i
, stabsize
= 0, stabstrsize
= 0;
3046 unsigned int stabs
= 0, stabstr
= 0;
3047 PIMAGE_NT_HEADERS nth
= (PIMAGE_NT_HEADERS
)_nth
;
3048 enum DbgInfoLoad dil
= DIL_ERROR
;
3050 pe_seg_ofs
= nth_ofs
+ OFFSET_OF(IMAGE_NT_HEADERS
, OptionalHeader
) +
3051 nth
->FileHeader
.SizeOfOptionalHeader
;
3053 for (i
= 0; i
< nth
->FileHeader
.NumberOfSections
; i
++, pe_seg_ofs
+= sizeof(pe_seg
)) {
3054 if (!DEBUG_READ_MEM_VERBOSE((void*)((char *)module
->load_addr
+ pe_seg_ofs
),
3055 &pe_seg
, sizeof(pe_seg
)))
3058 if (!strcasecmp(pe_seg
.Name
, ".stab")) {
3059 stabs
= pe_seg
.VirtualAddress
;
3060 stabsize
= pe_seg
.SizeOfRawData
;
3061 } else if (!strncasecmp(pe_seg
.Name
, ".stabstr", 8)) {
3062 stabstr
= pe_seg
.VirtualAddress
;
3063 stabstrsize
= pe_seg
.SizeOfRawData
;
3067 if (stabstrsize
&& stabsize
) {
3068 char* s1
= DBG_alloc(stabsize
+stabstrsize
);
3071 if (DEBUG_READ_MEM_VERBOSE((char*)module
->load_addr
+ stabs
, s1
, stabsize
) &&
3072 DEBUG_READ_MEM_VERBOSE((char*)module
->load_addr
+ stabstr
,
3073 s1
+ stabsize
, stabstrsize
)) {
3074 dil
= DEBUG_ParseStabs(s1
, 0, 0, stabsize
, stabsize
, stabstrsize
);
3076 DEBUG_Printf(DBG_CHN_MESG
, "couldn't read data block\n");
3080 DEBUG_Printf(DBG_CHN_MESG
, "couldn't alloc %d bytes\n",
3081 stabsize
+ stabstrsize
);