2 * File msc.c - read VC++ debug information from COFF and eventually
5 * Copyright (C) 1996, Eric Youngdale.
6 * Copyright (C) 1999, Ulrich Weigand.
8 * Note - this handles reading debug information for 32 bit applications
9 * that run under Windows-NT for example. I doubt that this would work well
10 * for 16 bit applications, but I don't think it really matters since the
11 * file format is different, and we should never get in here in such cases.
14 * Get 16 bit CV stuff working.
15 * Add symbol size to internal symbol table.
24 #define PATH_MAX _MAX_PATH
32 IMAGE_DEBUG_DIRECTORY dbgdir
;
39 #define MSC_INFO(module) ((MSC_DBG_INFO*)((module)->extra_info))
41 static int DEBUG_ProcessMSCDebugInfo(DBG_MODULE
* module
);
44 * dbg_filename must be at least MAX_PATHNAME_LEN bytes in size
46 static void DEBUG_LocateDebugInfoFile(const char *filename
, char *dbg_filename
)
48 char *str1
= DBG_alloc(MAX_PATHNAME_LEN
);
49 char *str2
= DBG_alloc(MAX_PATHNAME_LEN
*10);
53 file
= strrchr(filename
, '\\');
54 if( file
== NULL
) file
= filename
; else file
++;
56 if ((GetEnvironmentVariable("_NT_SYMBOL_PATH", str1
, MAX_PATHNAME_LEN
) &&
57 (SearchPath(str1
, file
, NULL
, MAX_PATHNAME_LEN
*10, str2
, &name_part
))) ||
58 (GetEnvironmentVariable("_NT_ALT_SYMBOL_PATH", str1
, MAX_PATHNAME_LEN
) &&
59 (SearchPath(str1
, file
, NULL
, MAX_PATHNAME_LEN
*10, str2
, &name_part
))) ||
60 (SearchPath(NULL
, file
, NULL
, MAX_PATHNAME_LEN
*10, str2
, &name_part
)))
61 lstrcpyn(dbg_filename
, str2
, MAX_PATHNAME_LEN
);
63 lstrcpyn(dbg_filename
, filename
, MAX_PATHNAME_LEN
);
68 /***********************************************************************
69 * DEBUG_MapDebugInfoFile
71 static void* DEBUG_MapDebugInfoFile(const char* name
, DWORD offset
, DWORD size
,
72 HANDLE
* hFile
, HANDLE
* hMap
)
75 DWORD g_offset
; /* offset aligned on map granuality */
76 DWORD g_size
; /* size to map, with offset aligned */
82 char filename
[MAX_PATHNAME_LEN
];
84 DEBUG_LocateDebugInfoFile(name
, filename
);
85 if ((*hFile
= OpenFile(filename
, &ofs
, OF_READ
)) == HFILE_ERROR
)
90 DWORD file_size
= GetFileSize(*hFile
, NULL
);
91 if (file_size
== (DWORD
)-1) return NULL
;
92 size
= file_size
- offset
;
95 g_offset
= offset
& ~0xFFFF; /* FIXME: is granularity portable ? */
96 g_size
= offset
+ size
- g_offset
;
98 if ((*hMap
= CreateFileMapping(*hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
)) == 0)
101 if ((ret
= MapViewOfFile(*hMap
, FILE_MAP_READ
, 0, g_offset
, g_size
)) != NULL
)
102 ret
+= offset
- g_offset
;
106 /***********************************************************************
107 * DEBUG_UnmapDebugInfoFile
109 static void DEBUG_UnmapDebugInfoFile(HANDLE hFile
, HANDLE hMap
, void* addr
)
111 if (addr
) UnmapViewOfFile(addr
);
112 if (hMap
) CloseHandle(hMap
);
113 if (hFile
) CloseHandle(hFile
);
125 * This is a convenience structure used to map portions of the
135 * This is how we reference the various record types.
137 union codeview_symbol
151 unsigned short symtype
;
152 unsigned char namelen
;
153 unsigned char name
[1];
160 unsigned int symtype
;
163 unsigned char namelen
;
164 unsigned char name
[1];
171 unsigned int pparent
;
175 unsigned short segment
;
176 unsigned short thunk_len
;
177 unsigned char thtype
;
178 unsigned char namelen
;
179 unsigned char name
[1];
186 unsigned int pparent
;
189 unsigned int proc_len
;
190 unsigned int debug_start
;
191 unsigned int debug_end
;
193 unsigned short segment
;
194 unsigned short proctype
;
196 unsigned char namelen
;
197 unsigned char name
[1];
204 unsigned int pparent
;
207 unsigned int proc_len
;
208 unsigned int debug_start
;
209 unsigned int debug_end
;
210 unsigned int proctype
;
212 unsigned short segment
;
214 unsigned char namelen
;
215 unsigned char name
[1];
220 short int len
; /* Total length of this entry */
221 short int id
; /* Always S_BPREL32 */
222 unsigned int offset
; /* Stack offset relative to BP */
223 unsigned short symtype
;
224 unsigned char namelen
;
225 unsigned char name
[1];
230 short int len
; /* Total length of this entry */
231 short int id
; /* Always S_BPREL32 */
232 unsigned int offset
; /* Stack offset relative to BP */
233 unsigned int symtype
;
234 unsigned char namelen
;
235 unsigned char name
[1];
254 unsigned char variant
[1];
261 unsigned int datatype
;
262 unsigned int attribute
;
263 unsigned char variant
[1];
271 unsigned char bitoff
;
281 unsigned char bitoff
;
290 unsigned char arrlen
;
291 unsigned char namelen
;
292 unsigned char name
[1];
299 unsigned int elemtype
;
300 unsigned int idxtype
;
301 unsigned char arrlen
;
302 unsigned char namelen
;
303 unsigned char name
[1];
315 unsigned short structlen
;
316 unsigned char namelen
;
317 unsigned char name
[1];
326 unsigned int fieldlist
;
327 unsigned int derived
;
329 unsigned short structlen
;
330 unsigned char namelen
;
331 unsigned char name
[1];
341 unsigned short un_len
;
342 unsigned char namelen
;
343 unsigned char name
[1];
353 unsigned short un_len
;
354 unsigned char namelen
;
355 unsigned char name
[1];
366 unsigned char namelen
;
367 unsigned char name
[1];
378 unsigned char namelen
;
379 unsigned char name
[1];
386 unsigned short int value
;
387 unsigned char namelen
;
388 unsigned char name
[1];
396 unsigned short int offset
;
397 unsigned char namelen
;
398 unsigned char name
[1];
406 unsigned short int offset
;
407 unsigned char namelen
;
408 unsigned char name
[1];
412 #define S_COMPILE 0x0001
413 #define S_REGISTER 0x0002
414 #define S_CONSTANT 0x0003
416 #define S_SSEARCH 0x0005
418 #define S_SKIP 0x0007
419 #define S_CVRESERVE 0x0008
420 #define S_OBJNAME 0x0009
421 #define S_ENDARG 0x000a
422 #define S_COBOLUDT 0x000b
423 #define S_MANYREG 0x000c
424 #define S_RETURN 0x000d
425 #define S_ENTRYTHIS 0x000e
427 #define S_BPREL 0x0200
428 #define S_LDATA 0x0201
429 #define S_GDATA 0x0202
431 #define S_LPROC 0x0204
432 #define S_GPROC 0x0205
433 #define S_THUNK 0x0206
434 #define S_BLOCK 0x0207
435 #define S_WITH 0x0208
436 #define S_LABEL 0x0209
437 #define S_CEXMODEL 0x020a
438 #define S_VFTPATH 0x020b
439 #define S_REGREL 0x020c
440 #define S_LTHREAD 0x020d
441 #define S_GTHREAD 0x020e
443 #define S_PROCREF 0x0400
444 #define S_DATAREF 0x0401
445 #define S_ALIGN 0x0402
446 #define S_LPROCREF 0x0403
448 #define S_REGISTER_32 0x1001 /* Variants with new 32-bit type indices */
449 #define S_CONSTANT_32 0x1002
450 #define S_UDT_32 0x1003
451 #define S_COBOLUDT_32 0x1004
452 #define S_MANYREG_32 0x1005
454 #define S_BPREL_32 0x1006
455 #define S_LDATA_32 0x1007
456 #define S_GDATA_32 0x1008
457 #define S_PUB_32 0x1009
458 #define S_LPROC_32 0x100a
459 #define S_GPROC_32 0x100b
460 #define S_VFTTABLE_32 0x100c
461 #define S_REGREL_32 0x100d
462 #define S_LTHREAD_32 0x100e
463 #define S_GTHREAD_32 0x100f
467 * This covers the basic datatypes that VC++ seems to be using these days.
468 * 32 bit mode only. There are additional numbers for the pointers in 16
469 * bit mode. There are many other types listed in the documents, but these
470 * are apparently not used by the compiler, or represent pointer types
473 #define T_NOTYPE 0x0000 /* Notype */
474 #define T_ABS 0x0001 /* Abs */
475 #define T_VOID 0x0003 /* Void */
476 #define T_CHAR 0x0010 /* signed char */
477 #define T_SHORT 0x0011 /* short */
478 #define T_LONG 0x0012 /* long */
479 #define T_QUAD 0x0013 /* long long */
480 #define T_UCHAR 0x0020 /* unsigned char */
481 #define T_USHORT 0x0021 /* unsigned short */
482 #define T_ULONG 0x0022 /* unsigned long */
483 #define T_UQUAD 0x0023 /* unsigned long long */
484 #define T_REAL32 0x0040 /* float */
485 #define T_REAL64 0x0041 /* double */
486 #define T_RCHAR 0x0070 /* real char */
487 #define T_WCHAR 0x0071 /* wide char */
488 #define T_INT4 0x0074 /* int */
489 #define T_UINT4 0x0075 /* unsigned int */
491 #define T_32PVOID 0x0403 /* 32 bit near pointer to void */
492 #define T_32PCHAR 0x0410 /* 16:32 near pointer to signed char */
493 #define T_32PSHORT 0x0411 /* 16:32 near pointer to short */
494 #define T_32PLONG 0x0412 /* 16:32 near pointer to int */
495 #define T_32PQUAD 0x0413 /* 16:32 near pointer to long long */
496 #define T_32PUCHAR 0x0420 /* 16:32 near pointer to unsigned char */
497 #define T_32PUSHORT 0x0421 /* 16:32 near pointer to unsigned short */
498 #define T_32PULONG 0x0422 /* 16:32 near pointer to unsigned int */
499 #define T_32PUQUAD 0x0423 /* 16:32 near pointer to long long */
500 #define T_32PREAL32 0x0440 /* 16:32 near pointer to float */
501 #define T_32PREAL64 0x0441 /* 16:32 near pointer to float */
502 #define T_32PRCHAR 0x0470 /* 16:32 near pointer to real char */
503 #define T_32PWCHAR 0x0471 /* 16:32 near pointer to real char */
504 #define T_32PINT4 0x0474 /* 16:32 near pointer to int */
505 #define T_32PUINT4 0x0475 /* 16:32 near pointer to unsigned int */
507 #define LF_MODIFIER 0x0001
508 #define LF_POINTER 0x0002
509 #define LF_ARRAY 0x0003
510 #define LF_CLASS 0x0004
511 #define LF_STRUCTURE 0x0005
512 #define LF_UNION 0x0006
513 #define LF_ENUM 0x0007
514 #define LF_PROCEDURE 0x0008
515 #define LF_MFUNCTION 0x0009
516 #define LF_VTSHAPE 0x000a
517 #define LF_COBOL0 0x000b
518 #define LF_COBOL1 0x000c
519 #define LF_BARRAY 0x000d
520 #define LF_LABEL 0x000e
521 #define LF_NULL 0x000f
522 #define LF_NOTTRAN 0x0010
523 #define LF_DIMARRAY 0x0011
524 #define LF_VFTPATH 0x0012
525 #define LF_PRECOMP 0x0013
526 #define LF_ENDPRECOMP 0x0014
527 #define LF_OEM 0x0015
528 #define LF_TYPESERVER 0x0016
530 #define LF_MODIFIER_32 0x1001 /* variants with new 32-bit type indices */
531 #define LF_POINTER_32 0x1002
532 #define LF_ARRAY_32 0x1003
533 #define LF_CLASS_32 0x1004
534 #define LF_STRUCTURE_32 0x1005
535 #define LF_UNION_32 0x1006
536 #define LF_ENUM_32 0x1007
537 #define LF_PROCEDURE_32 0x1008
538 #define LF_MFUNCTION_32 0x1009
539 #define LF_COBOL0_32 0x100a
540 #define LF_BARRAY_32 0x100b
541 #define LF_DIMARRAY_32 0x100c
542 #define LF_VFTPATH_32 0x100d
543 #define LF_PRECOMP_32 0x100e
544 #define LF_OEM_32 0x100f
546 #define LF_SKIP 0x0200
547 #define LF_ARGLIST 0x0201
548 #define LF_DEFARG 0x0202
549 #define LF_LIST 0x0203
550 #define LF_FIELDLIST 0x0204
551 #define LF_DERIVED 0x0205
552 #define LF_BITFIELD 0x0206
553 #define LF_METHODLIST 0x0207
554 #define LF_DIMCONU 0x0208
555 #define LF_DIMCONLU 0x0209
556 #define LF_DIMVARU 0x020a
557 #define LF_DIMVARLU 0x020b
558 #define LF_REFSYM 0x020c
560 #define LF_SKIP_32 0x1200 /* variants with new 32-bit type indices */
561 #define LF_ARGLIST_32 0x1201
562 #define LF_DEFARG_32 0x1202
563 #define LF_FIELDLIST_32 0x1203
564 #define LF_DERIVED_32 0x1204
565 #define LF_BITFIELD_32 0x1205
566 #define LF_METHODLIST_32 0x1206
567 #define LF_DIMCONU_32 0x1207
568 #define LF_DIMCONLU_32 0x1208
569 #define LF_DIMVARU_32 0x1209
570 #define LF_DIMVARLU_32 0x120a
572 #define LF_BCLASS 0x0400
573 #define LF_VBCLASS 0x0401
574 #define LF_IVBCLASS 0x0402
575 #define LF_ENUMERATE 0x0403
576 #define LF_FRIENDFCN 0x0404
577 #define LF_INDEX 0x0405
578 #define LF_MEMBER 0x0406
579 #define LF_STMEMBER 0x0407
580 #define LF_METHOD 0x0408
581 #define LF_NESTTYPE 0x0409
582 #define LF_VFUNCTAB 0x040a
583 #define LF_FRIENDCLS 0x040b
584 #define LF_ONEMETHOD 0x040c
585 #define LF_VFUNCOFF 0x040d
586 #define LF_NESTTYPEEX 0x040e
587 #define LF_MEMBERMODIFY 0x040f
589 #define LF_BCLASS_32 0x1400 /* variants with new 32-bit type indices */
590 #define LF_VBCLASS_32 0x1401
591 #define LF_IVBCLASS_32 0x1402
592 #define LF_FRIENDFCN_32 0x1403
593 #define LF_INDEX_32 0x1404
594 #define LF_MEMBER_32 0x1405
595 #define LF_STMEMBER_32 0x1406
596 #define LF_METHOD_32 0x1407
597 #define LF_NESTTYPE_32 0x1408
598 #define LF_VFUNCTAB_32 0x1409
599 #define LF_FRIENDCLS_32 0x140a
600 #define LF_ONEMETHOD_32 0x140b
601 #define LF_VFUNCOFF_32 0x140c
602 #define LF_NESTTYPEEX_32 0x140d
607 #define MAX_BUILTIN_TYPES 0x480
608 static struct datatype
* cv_basic_types
[MAX_BUILTIN_TYPES
];
609 static int num_cv_defined_types
= 0;
610 static struct datatype
**cv_defined_types
= NULL
;
613 * For the type CODEVIEW debug directory entries, the debug directory
614 * points to a structure like this. The cv_name field is the name
615 * of an external .PDB file.
620 unsigned int cv_timestamp
;
626 unsigned int DataType
;
634 * This is the header that the COFF variety of debug header points to.
638 unsigned int SymbolOffset
;
639 unsigned int N_Linenum
;
640 unsigned int LinenumberOffset
;
641 unsigned int Unused
[4];
645 unsigned int VirtualAddr
;
646 unsigned short int Linenum
;
650 unsigned int startaddr
;
651 unsigned int endaddr
;
655 struct name_hash
**entries
;
665 unsigned int NotLong
;
666 unsigned int StrTaboff
;
673 unsigned char NumberOfAuxSymbols
;
676 struct CoffAuxSection
{
678 unsigned short NumberOfRelocations
;
679 unsigned short NumberOfLinenumbers
;
680 unsigned int CheckSum
;
686 * These two structures are used in the directory within a .DBG file
687 * to locate the individual important bits that we might want to see.
690 short unsigned int dhsize
;
691 short unsigned int desize
;
693 unsigned int next_offset
;
698 short unsigned int subsect_number
;
699 short unsigned int module_number
;
705 * These are the values of interest that the subsect_number field takes.
707 #define sstAlignSym 0x125
708 #define sstSrcModule 0x127
710 struct codeview_linetab_hdr
717 unsigned short * linetab
;
718 unsigned int * offtab
;
723 struct datatype
* DEBUG_GetCVType(unsigned int typeno
)
725 struct datatype
* dt
= NULL
;
728 * Convert Codeview type numbers into something we can grok internally.
729 * Numbers < 0x1000 are all fixed builtin types. Numbers from 0x1000 and
730 * up are all user defined (structs, etc).
732 if( typeno
< 0x1000 )
734 if( typeno
< MAX_BUILTIN_TYPES
)
736 dt
= cv_basic_types
[typeno
];
741 if( typeno
- 0x1000 < num_cv_defined_types
)
743 dt
= cv_defined_types
[typeno
- 0x1000];
751 DEBUG_ParseTypeTable(char * table
, int len
)
755 enum debug_type fieldtype
;
759 struct datatype
* subtype
;
761 union codeview_type
* type
;
762 union codeview_type
* type2
;
763 struct datatype
* typeptr
;
768 while( ptr
.c
- table
< len
)
770 type
= (union codeview_type
*) ptr
.c
;
772 if( curr_type
- 0x1000 >= num_cv_defined_types
)
774 num_cv_defined_types
+= 0x100;
775 cv_defined_types
= (struct datatype
**) DBG_realloc(cv_defined_types
,
776 num_cv_defined_types
* sizeof(struct datatype
*));
777 memset(cv_defined_types
+ num_cv_defined_types
- 0x100,
779 0x100 * sizeof(struct datatype
*));
780 if( cv_defined_types
== NULL
)
786 switch(type
->generic
.id
)
789 cv_defined_types
[curr_type
- 0x1000] =
790 DEBUG_FindOrMakePointerType(DEBUG_GetCVType(type
->pointer
.datatype
));
793 cv_defined_types
[curr_type
- 0x1000] =
794 DEBUG_FindOrMakePointerType(DEBUG_GetCVType(type
->pointer32
.datatype
));
797 if( type
->array
.arrlen
>= 0x8000 )
800 * This is a numeric leaf, I am too lazy to handle this right
803 DEBUG_Printf(DBG_CHN_MESG
, "Ignoring large numberic leaf.\n");
806 if( type
->array
.namelen
!= 0 )
808 memset(symname
, 0, sizeof(symname
));
809 memcpy(symname
, type
->array
.name
, type
->array
.namelen
);
810 typeptr
= DEBUG_NewDataType(DT_ARRAY
, symname
);
814 typeptr
= DEBUG_NewDataType(DT_ARRAY
, NULL
);
816 cv_defined_types
[curr_type
- 0x1000] = typeptr
;
818 subtype
= DEBUG_GetCVType(type
->array
.elemtype
);
819 if( (subtype
== NULL
)
820 || (elem_size
= DEBUG_GetObjectSize(subtype
)) == 0 )
826 arr_max
= type
->array
.arrlen
/ DEBUG_GetObjectSize(subtype
);
829 DEBUG_SetArrayParams(typeptr
, 0, arr_max
, subtype
);
832 if( type
->array32
.arrlen
>= 0x8000 )
835 * This is a numeric leaf, I am too lazy to handle this right
838 DEBUG_Printf(DBG_CHN_MESG
, "Ignoring large numberic leaf.\n");
841 if( type
->array32
.namelen
!= 0 )
843 memset(symname
, 0, sizeof(symname
));
844 memcpy(symname
, type
->array32
.name
, type
->array32
.namelen
);
845 typeptr
= DEBUG_NewDataType(DT_ARRAY
, symname
);
849 typeptr
= DEBUG_NewDataType(DT_ARRAY
, NULL
);
851 cv_defined_types
[curr_type
- 0x1000] = typeptr
;
853 subtype
= DEBUG_GetCVType(type
->array32
.elemtype
);
854 if( (subtype
== NULL
)
855 || (elem_size
= DEBUG_GetObjectSize(subtype
)) == 0 )
861 arr_max
= type
->array32
.arrlen
/ DEBUG_GetObjectSize(subtype
);
864 DEBUG_SetArrayParams(typeptr
, 0, arr_max
, subtype
);
868 * This is where the basic list of fields is defined for
869 * structures and classes.
871 * First, we need to look ahead and see whether we are building
872 * a fieldlist for an enum or a struct.
875 type2
= (union codeview_type
*) ptr2
.c
;
876 if( type2
->member
.id
== LF_MEMBER
)
878 typeptr
= DEBUG_NewDataType(DT_STRUCT
, NULL
);
879 fieldtype
= DT_STRUCT
;
881 else if( type2
->member
.id
== LF_ENUMERATE
)
883 typeptr
= DEBUG_NewDataType(DT_ENUM
, NULL
);
891 cv_defined_types
[curr_type
- 0x1000] = typeptr
;
892 while( ptr2
.c
< (ptr
.c
+ ((type
->generic
.len
+ 3) & ~3)) )
894 type2
= (union codeview_type
*) ptr2
.c
;
895 if( type2
->member
.id
== LF_MEMBER
&& fieldtype
== DT_STRUCT
)
897 memset(symname
, 0, sizeof(symname
));
898 memcpy(symname
, type2
->member
.name
, type2
->member
.namelen
);
900 subtype
= DEBUG_GetCVType(type2
->member
.type
);
902 if( subtype
!= NULL
)
904 elem_size
= DEBUG_GetObjectSize(subtype
);
907 if( type2
->member
.offset
>= 0x8000 )
910 * This is a numeric leaf, I am too lazy to handle this right
913 DEBUG_Printf(DBG_CHN_MESG
, "Ignoring large numberic leaf.\n");
917 DEBUG_AddStructElement(typeptr
, symname
, subtype
,
918 type2
->member
.offset
<< 3,
922 else if( type2
->member
.id
== LF_ENUMERATE
&& fieldtype
== DT_ENUM
)
924 memset(symname
, 0, sizeof(symname
));
925 memcpy(symname
, type2
->enumerate
.name
, type2
->enumerate
.namelen
);
927 if( type2
->enumerate
.value
>= 0x8000 )
930 * This is a numeric leaf, I am too lazy to handle this right
933 DEBUG_Printf(DBG_CHN_MESG
, "Ignoring large numberic leaf.\n");
937 DEBUG_AddStructElement(typeptr
, symname
, NULL
,
938 type2
->enumerate
.value
, 0);
944 * Something else I have never seen before. Either wrong type of
945 * object in the fieldlist, or some other problem which I wouldn't
946 * really know how to handle until it came up.
948 DEBUG_Printf(DBG_CHN_MESG
, "Unexpected entry in fieldlist\n");
953 ptr2
.c
+= ((type2
->member
.namelen
+ 9 + 3) & ~3);
956 case LF_FIELDLIST_32
:
958 * This is where the basic list of fields is defined for
959 * structures and classes.
961 * First, we need to look ahead and see whether we are building
962 * a fieldlist for an enum or a struct.
965 type2
= (union codeview_type
*) ptr2
.c
;
966 if( type2
->member32
.id
== LF_MEMBER_32
)
968 typeptr
= DEBUG_NewDataType(DT_STRUCT
, NULL
);
969 fieldtype
= DT_STRUCT
;
971 else if( type2
->member32
.id
== LF_ENUMERATE
)
973 typeptr
= DEBUG_NewDataType(DT_ENUM
, NULL
);
981 cv_defined_types
[curr_type
- 0x1000] = typeptr
;
982 while( ptr2
.c
< (ptr
.c
+ ((type
->generic
.len
+ 3) & ~3)) )
984 type2
= (union codeview_type
*) ptr2
.c
;
985 if( type2
->member
.id
== LF_MEMBER_32
&& fieldtype
== DT_STRUCT
)
987 memset(symname
, 0, sizeof(symname
));
988 memcpy(symname
, type2
->member32
.name
, type2
->member32
.namelen
);
990 subtype
= DEBUG_GetCVType(type2
->member32
.type
);
992 if( subtype
!= NULL
)
994 elem_size
= DEBUG_GetObjectSize(subtype
);
997 if( type2
->member32
.offset
>= 0x8000 )
1000 * This is a numeric leaf, I am too lazy to handle this right
1003 DEBUG_Printf(DBG_CHN_MESG
, "Ignoring large numberic leaf.\n");
1007 DEBUG_AddStructElement(typeptr
, symname
, subtype
,
1008 type2
->member32
.offset
<< 3,
1012 else if( type2
->member32
.id
== LF_ENUMERATE
&& fieldtype
== DT_ENUM
)
1014 memset(symname
, 0, sizeof(symname
));
1015 memcpy(symname
, type2
->enumerate
.name
, type2
->enumerate
.namelen
);
1017 if( type2
->enumerate
.value
>= 0x8000 )
1020 * This is a numeric leaf, I am too lazy to handle this right
1023 DEBUG_Printf(DBG_CHN_MESG
, "Ignoring large numberic leaf.\n");
1027 DEBUG_AddStructElement(typeptr
, symname
, NULL
,
1028 type2
->enumerate
.value
, 0);
1034 * Something else I have never seen before. Either wrong type of
1035 * object in the fieldlist, or some other problem which I wouldn't
1036 * really know how to handle until it came up.
1038 DEBUG_Printf(DBG_CHN_MESG
, "Unexpected entry in fieldlist\n");
1043 ptr2
.c
+= ((type2
->member32
.namelen
+ 9 + 3) & ~3);
1048 if( type
->structure
.structlen
>= 0x8000 )
1051 * This is a numeric leaf, I am too lazy to handle this right
1054 DEBUG_Printf(DBG_CHN_MESG
, "Ignoring large numberic leaf.\n");
1057 memset(symname
, 0, sizeof(symname
));
1058 memcpy(symname
, type
->structure
.name
, type
->structure
.namelen
);
1059 if( strcmp(symname
, "__unnamed") == 0 )
1061 typeptr
= DEBUG_NewDataType(DT_STRUCT
, NULL
);
1065 typeptr
= DEBUG_NewDataType(DT_STRUCT
, symname
);
1067 cv_defined_types
[curr_type
- 0x1000] = typeptr
;
1070 * Now copy the relevant bits from the fieldlist that we specified.
1072 subtype
= DEBUG_GetCVType(type
->structure
.fieldlist
);
1074 if( subtype
!= NULL
)
1076 DEBUG_SetStructSize(typeptr
, type
->structure
.structlen
);
1077 DEBUG_CopyFieldlist(typeptr
, subtype
);
1080 case LF_STRUCTURE_32
:
1082 if( type
->structure32
.structlen
>= 0x8000 )
1085 * This is a numeric leaf, I am too lazy to handle this right
1088 DEBUG_Printf(DBG_CHN_MESG
, "Ignoring large numberic leaf.\n");
1091 memset(symname
, 0, sizeof(symname
));
1092 memcpy(symname
, type
->structure32
.name
, type
->structure32
.namelen
);
1093 if( strcmp(symname
, "__unnamed") == 0 )
1095 typeptr
= DEBUG_NewDataType(DT_STRUCT
, NULL
);
1099 typeptr
= DEBUG_NewDataType(DT_STRUCT
, symname
);
1101 cv_defined_types
[curr_type
- 0x1000] = typeptr
;
1104 * Now copy the relevant bits from the fieldlist that we specified.
1106 subtype
= DEBUG_GetCVType(type
->structure32
.fieldlist
);
1108 if( subtype
!= NULL
)
1110 DEBUG_SetStructSize(typeptr
, type
->structure32
.structlen
);
1111 DEBUG_CopyFieldlist(typeptr
, subtype
);
1115 if( type
->t_union
.un_len
>= 0x8000 )
1118 * This is a numeric leaf, I am too lazy to handle this right
1121 DEBUG_Printf(DBG_CHN_MESG
, "Ignoring large numberic leaf.\n");
1124 memset(symname
, 0, sizeof(symname
));
1125 memcpy(symname
, type
->t_union
.name
, type
->t_union
.namelen
);
1127 if( strcmp(symname
, "__unnamed") == 0 )
1129 typeptr
= DEBUG_NewDataType(DT_STRUCT
, NULL
);
1133 typeptr
= DEBUG_NewDataType(DT_STRUCT
, symname
);
1136 cv_defined_types
[curr_type
- 0x1000] = typeptr
;
1139 * Now copy the relevant bits from the fieldlist that we specified.
1141 subtype
= DEBUG_GetCVType(type
->t_union
.field
);
1143 if( subtype
!= NULL
)
1145 DEBUG_SetStructSize(typeptr
, type
->t_union
.un_len
);
1146 DEBUG_CopyFieldlist(typeptr
, subtype
);
1150 if( type
->t_union32
.un_len
>= 0x8000 )
1153 * This is a numeric leaf, I am too lazy to handle this right
1156 DEBUG_Printf(DBG_CHN_MESG
, "Ignoring large numberic leaf.\n");
1159 memset(symname
, 0, sizeof(symname
));
1160 memcpy(symname
, type
->t_union32
.name
, type
->t_union32
.namelen
);
1162 if( strcmp(symname
, "__unnamed") == 0 )
1164 typeptr
= DEBUG_NewDataType(DT_STRUCT
, NULL
);
1168 typeptr
= DEBUG_NewDataType(DT_STRUCT
, symname
);
1171 cv_defined_types
[curr_type
- 0x1000] = typeptr
;
1174 * Now copy the relevant bits from the fieldlist that we specified.
1176 subtype
= DEBUG_GetCVType(type
->t_union32
.field
);
1178 if( subtype
!= NULL
)
1180 DEBUG_SetStructSize(typeptr
, type
->t_union32
.un_len
);
1181 DEBUG_CopyFieldlist(typeptr
, subtype
);
1185 typeptr
= DEBUG_NewDataType(DT_BITFIELD
, NULL
);
1186 cv_defined_types
[curr_type
- 0x1000] = typeptr
;
1187 DEBUG_SetBitfieldParams(typeptr
, type
->bitfield
.bitoff
,
1188 type
->bitfield
.nbits
,
1189 DEBUG_GetCVType(type
->bitfield
.type
));
1191 case LF_BITFIELD_32
:
1192 typeptr
= DEBUG_NewDataType(DT_BITFIELD
, NULL
);
1193 cv_defined_types
[curr_type
- 0x1000] = typeptr
;
1194 DEBUG_SetBitfieldParams(typeptr
, type
->bitfield32
.bitoff
,
1195 type
->bitfield32
.nbits
,
1196 DEBUG_GetCVType(type
->bitfield32
.type
));
1199 memset(symname
, 0, sizeof(symname
));
1200 memcpy(symname
, type
->enumeration
.name
, type
->enumeration
.namelen
);
1201 typeptr
= DEBUG_NewDataType(DT_ENUM
, symname
);
1202 cv_defined_types
[curr_type
- 0x1000] = typeptr
;
1205 * Now copy the relevant bits from the fieldlist that we specified.
1207 subtype
= DEBUG_GetCVType(type
->enumeration
.field
);
1209 if( subtype
!= NULL
)
1211 DEBUG_CopyFieldlist(typeptr
, subtype
);
1215 memset(symname
, 0, sizeof(symname
));
1216 memcpy(symname
, type
->enumeration32
.name
, type
->enumeration32
.namelen
);
1217 typeptr
= DEBUG_NewDataType(DT_ENUM
, symname
);
1218 cv_defined_types
[curr_type
- 0x1000] = typeptr
;
1221 * Now copy the relevant bits from the fieldlist that we specified.
1223 subtype
= DEBUG_GetCVType(type
->enumeration32
.field
);
1225 if( subtype
!= NULL
)
1227 DEBUG_CopyFieldlist(typeptr
, subtype
);
1234 ptr
.c
+= (type
->generic
.len
+ 3) & ~3;
1241 DEBUG_InitCVDataTypes(void)
1244 * These are the common builtin types that are used by VC++.
1246 cv_basic_types
[T_NOTYPE
] = NULL
;
1247 cv_basic_types
[T_ABS
] = NULL
;
1248 cv_basic_types
[T_VOID
] = DEBUG_NewDataType(DT_BASIC
, "void");
1249 cv_basic_types
[T_CHAR
] = DEBUG_NewDataType(DT_BASIC
, "char");
1250 cv_basic_types
[T_SHORT
] = DEBUG_NewDataType(DT_BASIC
, "short int");
1251 cv_basic_types
[T_LONG
] = DEBUG_NewDataType(DT_BASIC
, "long int");
1252 cv_basic_types
[T_QUAD
] = DEBUG_NewDataType(DT_BASIC
, "long long int");
1253 cv_basic_types
[T_UCHAR
] = DEBUG_NewDataType(DT_BASIC
, "unsigned char");
1254 cv_basic_types
[T_USHORT
] = DEBUG_NewDataType(DT_BASIC
, "short unsigned int");
1255 cv_basic_types
[T_ULONG
] = DEBUG_NewDataType(DT_BASIC
, "long unsigned int");
1256 cv_basic_types
[T_UQUAD
] = DEBUG_NewDataType(DT_BASIC
, "long long unsigned int");
1257 cv_basic_types
[T_REAL32
] = DEBUG_NewDataType(DT_BASIC
, "float");
1258 cv_basic_types
[T_REAL64
] = DEBUG_NewDataType(DT_BASIC
, "double");
1259 cv_basic_types
[T_RCHAR
] = DEBUG_NewDataType(DT_BASIC
, "char");
1260 cv_basic_types
[T_WCHAR
] = DEBUG_NewDataType(DT_BASIC
, "short");
1261 cv_basic_types
[T_INT4
] = DEBUG_NewDataType(DT_BASIC
, "int");
1262 cv_basic_types
[T_UINT4
] = DEBUG_NewDataType(DT_BASIC
, "unsigned int");
1264 cv_basic_types
[T_32PVOID
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_VOID
]);
1265 cv_basic_types
[T_32PCHAR
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_CHAR
]);
1266 cv_basic_types
[T_32PSHORT
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_SHORT
]);
1267 cv_basic_types
[T_32PLONG
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_LONG
]);
1268 cv_basic_types
[T_32PQUAD
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_QUAD
]);
1269 cv_basic_types
[T_32PUCHAR
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_UCHAR
]);
1270 cv_basic_types
[T_32PUSHORT
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_USHORT
]);
1271 cv_basic_types
[T_32PULONG
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_ULONG
]);
1272 cv_basic_types
[T_32PUQUAD
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_UQUAD
]);
1273 cv_basic_types
[T_32PREAL32
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_REAL32
]);
1274 cv_basic_types
[T_32PREAL64
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_REAL64
]);
1275 cv_basic_types
[T_32PRCHAR
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_RCHAR
]);
1276 cv_basic_types
[T_32PWCHAR
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_WCHAR
]);
1277 cv_basic_types
[T_32PINT4
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_INT4
]);
1278 cv_basic_types
[T_32PUINT4
] = DEBUG_FindOrMakePointerType(cv_basic_types
[T_UINT4
]);
1282 * In this function, we keep track of deferred debugging information
1283 * that we may need later if we were to need to use the internal debugger.
1284 * We don't fully process it here for performance reasons.
1287 DEBUG_RegisterMSCDebugInfo(DBG_MODULE
* module
, HANDLE hFile
, void* _nth
, unsigned long nth_ofs
)
1289 int has_codeview
= FALSE
;
1291 IMAGE_DEBUG_DIRECTORY dbg
;
1292 u_long v_addr
, size
, orig_size
;
1293 PIMAGE_NT_HEADERS nth
= (PIMAGE_NT_HEADERS
)_nth
;
1295 orig_size
= nth
->OptionalHeader
.DataDirectory
[IMAGE_DIRECTORY_ENTRY_DEBUG
].Size
;
1297 v_addr
= nth
->OptionalHeader
.DataDirectory
[IMAGE_DIRECTORY_ENTRY_DEBUG
].VirtualAddress
;
1298 for(size
= orig_size
; size
>= sizeof(dbg
); size
-= sizeof(dbg
))
1300 if (!DEBUG_READ_MEM_VERBOSE((void*)((char *) module
->load_addr
+ v_addr
), &dbg
, sizeof(dbg
))) continue;
1304 case IMAGE_DEBUG_TYPE_CODEVIEW
:
1305 case IMAGE_DEBUG_TYPE_MISC
:
1306 has_codeview
= TRUE
;
1309 v_addr
+= sizeof(dbg
);
1312 v_addr
= nth
->OptionalHeader
.DataDirectory
[IMAGE_DIRECTORY_ENTRY_DEBUG
].VirtualAddress
;
1313 for(size
= orig_size
; size
>= sizeof(dbg
); size
-= sizeof(dbg
))
1315 if (!DEBUG_READ_MEM_VERBOSE((void*)((char *)module
->load_addr
+ v_addr
), &dbg
, sizeof(dbg
))) continue;
1319 case IMAGE_DEBUG_TYPE_COFF
:
1321 * If we have both codeview and COFF debug info, ignore the
1322 * coff debug info as it would just confuse us, and it is
1325 * FIXME - this is broken - if we cannot find the PDB file, then
1326 * we end up with no debugging info at all. In this case, we
1327 * should use the COFF info as a backup.
1333 case IMAGE_DEBUG_TYPE_CODEVIEW
:
1334 case IMAGE_DEBUG_TYPE_MISC
:
1336 * This is usually an indirection to a .DBG file.
1337 * This is similar to (but a slightly older format) from the
1340 * First check to see if the image was 'stripped'. If so, it
1341 * means that this entry points to a .DBG file. Otherwise,
1342 * it just points to itself, and we can ignore this.
1345 if( (dbg
.Type
!= IMAGE_DEBUG_TYPE_MISC
) ||
1346 (nth
->FileHeader
.Characteristics
& IMAGE_FILE_DEBUG_STRIPPED
) != 0 )
1349 * Read the important bits. What we do after this depends
1350 * upon the type, but this is always enough so we are able
1351 * to proceed if we know what we need to do next.
1353 /* basically, the PE loader maps all sections (data, resources...), but doesn't map
1354 * the DataDirectory array's content. One its entry contains the *beloved*
1355 * debug information. (Note the DataDirectory is mapped, not its content)
1360 DEBUG_Printf(DBG_CHN_TRACE
, "PE debugging info at %ld<%ld>\n", dbg
.PointerToRawData
, dbg
.SizeOfData
);
1361 dbg_info
= DEBUG_MapDebugInfoFile(NULL
, dbg
.PointerToRawData
, dbg
.SizeOfData
,
1364 if (dbg_info
!= NULL
&&
1365 (module
->extra_info
= DBG_alloc(sizeof(MSC_DBG_INFO
))) != NULL
) {
1366 MSC_INFO(module
)->dbg_info
= dbg_info
;
1367 MSC_INFO(module
)->dbg_size
= dbg
.SizeOfData
;
1368 MSC_INFO(module
)->dbgdir
= dbg
;
1369 MSC_INFO(module
)->sect_ofs
= nth_ofs
+ OFFSET_OF(IMAGE_NT_HEADERS
, OptionalHeader
) +
1370 nth
->FileHeader
.SizeOfOptionalHeader
;
1371 MSC_INFO(module
)->nsect
= nth
->FileHeader
.NumberOfSections
;
1372 DEBUG_ProcessMSCDebugInfo(module
);
1373 DBG_free(MSC_INFO(module
));
1374 MSC_INFO(module
) = NULL
;
1376 DEBUG_UnmapDebugInfoFile(0, hMap
, dbg_info
);
1383 v_addr
+= sizeof(dbg
);
1385 DEBUG_CurrProcess
->next_index
++;
1391 /* look for stabs information in PE header (it's how mingw compiler provides its
1392 * debugging information), and also wine PE <-> ELF linking thru .wsolnk sections
1394 int DEBUG_RegisterStabsDebugInfo(DBG_MODULE
* module
, HANDLE hFile
, void* _nth
,
1395 unsigned long nth_ofs
)
1397 IMAGE_SECTION_HEADER pe_seg
;
1398 unsigned long pe_seg_ofs
;
1399 int i
, stabsize
= 0, stabstrsize
= 0, xcnlnksize
= 0;
1400 unsigned int stabs
= 0, stabstr
= 0, xcnlnk
= 0;
1401 PIMAGE_NT_HEADERS nth
= (PIMAGE_NT_HEADERS
)_nth
;
1403 pe_seg_ofs
= nth_ofs
+ OFFSET_OF(IMAGE_NT_HEADERS
, OptionalHeader
) +
1404 nth
->FileHeader
.SizeOfOptionalHeader
;
1406 for (i
= 0; i
< nth
->FileHeader
.NumberOfSections
; i
++, pe_seg_ofs
+= sizeof(pe_seg
)) {
1407 if (!DEBUG_READ_MEM_VERBOSE((void*)((char *)module
->load_addr
+ pe_seg_ofs
),
1408 &pe_seg
, sizeof(pe_seg
)))
1411 if (!strcasecmp(pe_seg
.Name
, ".stab")) {
1412 stabs
= pe_seg
.VirtualAddress
;
1413 stabsize
= pe_seg
.SizeOfRawData
;
1414 } else if (!strncasecmp(pe_seg
.Name
, ".stabstr", 8)) {
1415 stabstr
= pe_seg
.VirtualAddress
;
1416 stabstrsize
= pe_seg
.SizeOfRawData
;
1417 } else if (!strncasecmp(pe_seg
.Name
, ".xcnlnk", 7)) {
1418 xcnlnk
= pe_seg
.VirtualAddress
;
1419 xcnlnksize
= pe_seg
.SizeOfRawData
;
1423 if (stabstrsize
&& stabsize
) {
1424 char* s1
= DBG_alloc(stabsize
+stabstrsize
);
1427 if (DEBUG_READ_MEM_VERBOSE((char*)module
->load_addr
+ stabs
, s1
, stabsize
) &&
1428 DEBUG_READ_MEM_VERBOSE((char*)module
->load_addr
+ stabstr
,
1429 s1
+ stabsize
, stabstrsize
)) {
1430 DEBUG_ParseStabs(s1
, 0, 0, stabsize
, stabsize
, stabstrsize
);
1432 DEBUG_Printf(DBG_CHN_MESG
, "couldn't read data block\n");
1436 DEBUG_Printf(DBG_CHN_MESG
, "couldn't alloc %d bytes\n",
1437 stabsize
+ stabstrsize
);
1444 if (DEBUG_READ_MEM_VERBOSE((char*)module
->load_addr
+ xcnlnk
, &addr
,
1446 DEBUG_READ_MEM_VERBOSE((char*)addr
, bufstr
, sizeof(bufstr
))) {
1447 bufstr
[sizeof(bufstr
) - 1] = 0;
1448 DEBUG_Printf(DBG_CHN_TRACE
, "Got xcnlnk: argv0 '%s'\n", bufstr
);
1449 DEBUG_ReadExecutableDbgInfo(bufstr
);
1456 * Process COFF debugging information embedded in a Win32 application.
1461 DEBUG_ProcessCoff(DBG_MODULE
* module
)
1463 struct CoffAuxSection
* aux
;
1464 struct CoffDebug
* coff
;
1465 struct CoffFiles
* coff_files
= NULL
;
1466 struct CoffLinenum
* coff_linetab
;
1468 struct CoffSymbol
* coff_sym
;
1469 struct CoffSymbol
* coff_symbol
;
1470 struct CoffFiles
* curr_file
= NULL
;
1474 struct CoffLinenum
* linepnt
;
1479 DBG_VALUE new_value
;
1481 int nfiles_alloc
= 0;
1482 struct CoffFiles orig_file
;
1484 char * this_file
= NULL
;
1486 coff
= (struct CoffDebug
*) MSC_INFO(module
)->dbg_info
;
1488 coff_symbol
= (struct CoffSymbol
*) ((unsigned int) coff
+ coff
->SymbolOffset
);
1489 coff_linetab
= (struct CoffLinenum
*) ((unsigned int) coff
+ coff
->LinenumberOffset
);
1490 coff_strtab
= (char *) ((unsigned int) coff_symbol
+ 18*coff
->N_Sym
);
1494 new_value
.cookie
= DV_TARGET
;
1495 new_value
.type
= NULL
;
1497 for(i
=0; i
< coff
->N_Sym
; i
++ )
1500 * We do this because some compilers (i.e. gcc) incorrectly
1501 * pad the structure up to a 4 byte boundary. The structure
1502 * is really only 18 bytes long, so we have to manually make sure
1505 * FIXME - there must be a way to have autoconf figure out the
1506 * correct compiler option for this. If it is always gcc, that
1507 * makes life simpler, but I don't want to force this.
1509 coff_sym
= (struct CoffSymbol
*) ((unsigned int) coff_symbol
+ 18*i
);
1510 naux
= coff_sym
->NumberOfAuxSymbols
;
1512 if( coff_sym
->StorageClass
== IMAGE_SYM_CLASS_FILE
)
1514 if( nfiles
+ 1 >= nfiles_alloc
)
1517 coff_files
= (struct CoffFiles
*) DBG_realloc(coff_files
,
1518 nfiles_alloc
* sizeof(struct CoffFiles
));
1520 curr_file
= coff_files
+ nfiles
;
1522 curr_file
->startaddr
= 0xffffffff;
1523 curr_file
->endaddr
= 0;
1524 curr_file
->filename
= ((char *) coff_sym
) + 18;
1525 curr_file
->linetab_offset
= -1;
1526 curr_file
->linecnt
= 0;
1527 curr_file
->entries
= NULL
;
1528 curr_file
->neps
= curr_file
->neps_alloc
= 0;
1529 DEBUG_Printf(DBG_CHN_TRACE
,"New file %s\n", curr_file
->filename
);
1535 * This guy marks the size and location of the text section
1536 * for the current file. We need to keep track of this so
1537 * we can figure out what file the different global functions
1540 if( (coff_sym
->StorageClass
== IMAGE_SYM_CLASS_STATIC
)
1542 && (coff_sym
->Type
== 0)
1543 && (coff_sym
->SectionNumber
== 1) )
1545 aux
= (struct CoffAuxSection
*) ((unsigned int) coff_sym
+ 18);
1547 if( curr_file
->linetab_offset
!= -1 )
1550 DEBUG_Printf(DBG_CHN_TRACE
, "Duplicating sect from %s: %x %x %x %d %d\n",
1551 curr_file
->filename
,
1553 aux
->NumberOfRelocations
,
1554 aux
->NumberOfLinenumbers
,
1557 DEBUG_Printf(DBG_CHN_TRACE
, "More sect %d %x %d %d %d\n",
1558 coff_sym
->SectionNumber
,
1561 coff_sym
->StorageClass
,
1562 coff_sym
->NumberOfAuxSymbols
);
1566 * Save this so we can copy bits from it.
1568 orig_file
= *curr_file
;
1571 * Duplicate the file entry. We have no way to describe
1572 * multiple text sections in our current way of handling things.
1574 if( nfiles
+ 1 >= nfiles_alloc
)
1577 coff_files
= (struct CoffFiles
*) DBG_realloc(coff_files
,
1578 nfiles_alloc
* sizeof(struct CoffFiles
));
1580 curr_file
= coff_files
+ nfiles
;
1582 curr_file
->startaddr
= 0xffffffff;
1583 curr_file
->endaddr
= 0;
1584 curr_file
->filename
= orig_file
.filename
;
1585 curr_file
->linetab_offset
= -1;
1586 curr_file
->linecnt
= 0;
1587 curr_file
->entries
= NULL
;
1588 curr_file
->neps
= curr_file
->neps_alloc
= 0;
1593 DEBUG_Printf(DBG_CHN_TRACE
, "New text sect from %s: %x %x %x %d %d\n",
1594 curr_file
->filename
,
1596 aux
->NumberOfRelocations
,
1597 aux
->NumberOfLinenumbers
,
1603 if( curr_file
->startaddr
> coff_sym
->Value
)
1605 curr_file
->startaddr
= coff_sym
->Value
;
1608 if( curr_file
->startaddr
> coff_sym
->Value
)
1610 curr_file
->startaddr
= coff_sym
->Value
;
1613 if( curr_file
->endaddr
< coff_sym
->Value
+ aux
->Length
)
1615 curr_file
->endaddr
= coff_sym
->Value
+ aux
->Length
;
1618 curr_file
->linetab_offset
= linetab_indx
;
1619 curr_file
->linecnt
= aux
->NumberOfLinenumbers
;
1620 linetab_indx
+= aux
->NumberOfLinenumbers
;
1625 if( (coff_sym
->StorageClass
== IMAGE_SYM_CLASS_STATIC
)
1627 && (coff_sym
->SectionNumber
== 1) )
1630 * This is a normal static function when naux == 0.
1631 * Just register it. The current file is the correct
1632 * one in this instance.
1634 if( coff_sym
->N
.Name
.NotLong
)
1636 memcpy(namebuff
, coff_sym
->N
.ShortName
, 8);
1638 nampnt
= &namebuff
[0];
1642 nampnt
= coff_strtab
+ coff_sym
->N
.Name
.StrTaboff
;
1645 if( nampnt
[0] == '_' )
1650 new_value
.addr
.seg
= 0;
1651 new_value
.addr
.off
= (int) ((char *)module
->load_addr
+ coff_sym
->Value
);
1653 if( curr_file
->neps
+ 1 >= curr_file
->neps_alloc
)
1655 curr_file
->neps_alloc
+= 10;
1656 curr_file
->entries
= (struct name_hash
**)
1657 DBG_realloc(curr_file
->entries
,
1658 curr_file
->neps_alloc
* sizeof(struct name_hash
*));
1661 DEBUG_Printf(DBG_CHN_TRACE
,"\tAdding static symbol %s\n", nampnt
);
1663 curr_file
->entries
[curr_file
->neps
++] =
1664 DEBUG_AddSymbol( nampnt
, &new_value
, this_file
, SYM_WIN32
);
1669 if( (coff_sym
->StorageClass
== IMAGE_SYM_CLASS_EXTERNAL
)
1670 && ISFCN(coff_sym
->Type
)
1671 && (coff_sym
->SectionNumber
> 0) )
1673 if( coff_sym
->N
.Name
.NotLong
)
1675 memcpy(namebuff
, coff_sym
->N
.ShortName
, 8);
1677 nampnt
= &namebuff
[0];
1681 nampnt
= coff_strtab
+ coff_sym
->N
.Name
.StrTaboff
;
1685 if( nampnt
[0] == '_' )
1690 new_value
.addr
.seg
= 0;
1691 new_value
.addr
.off
= (int) ((char *)module
->load_addr
+ coff_sym
->Value
);
1694 DEBUG_Printf(DBG_CHN_TRACE
, "%d: %x %s\n", i
, new_value
.addr
.off
, nampnt
);
1696 DEBUG_Printf(DBG_CHN_TRACE
,"\tAdding global symbol %s\n", nampnt
);
1700 * Now we need to figure out which file this guy belongs to.
1703 for(j
=0; j
< nfiles
; j
++)
1705 if( coff_files
[j
].startaddr
<= coff_sym
->Value
1706 && coff_files
[j
].endaddr
> coff_sym
->Value
)
1708 this_file
= coff_files
[j
].filename
;
1712 if( coff_files
[j
].neps
+ 1 >= coff_files
[j
].neps_alloc
)
1714 coff_files
[j
].neps_alloc
+= 10;
1715 coff_files
[j
].entries
= (struct name_hash
**)
1716 DBG_realloc(coff_files
[j
].entries
,
1717 coff_files
[j
].neps_alloc
* sizeof(struct name_hash
*));
1719 coff_files
[j
].entries
[coff_files
[j
].neps
++] =
1720 DEBUG_AddSymbol( nampnt
, &new_value
, this_file
, SYM_WIN32
);
1725 if( (coff_sym
->StorageClass
== IMAGE_SYM_CLASS_EXTERNAL
)
1726 && (coff_sym
->SectionNumber
> 0) )
1729 * Similar to above, but for the case of data symbols.
1730 * These aren't treated as entrypoints.
1732 if( coff_sym
->N
.Name
.NotLong
)
1734 memcpy(namebuff
, coff_sym
->N
.ShortName
, 8);
1736 nampnt
= &namebuff
[0];
1740 nampnt
= coff_strtab
+ coff_sym
->N
.Name
.StrTaboff
;
1744 if( nampnt
[0] == '_' )
1749 new_value
.addr
.seg
= 0;
1750 new_value
.addr
.off
= (int) ((char *)module
->load_addr
+ coff_sym
->Value
);
1753 DEBUG_Printf(DBG_CHN_TRACE
, "%d: %x %s\n", i
, new_value
.addr
.off
, nampnt
);
1755 DEBUG_Printf(DBG_CHN_TRACE
,"\tAdding global data symbol %s\n", nampnt
);
1759 * Now we need to figure out which file this guy belongs to.
1761 DEBUG_AddSymbol( nampnt
, &new_value
, NULL
, SYM_WIN32
);
1766 if( (coff_sym
->StorageClass
== IMAGE_SYM_CLASS_STATIC
)
1770 * Ignore these. They don't have anything to do with
1778 DEBUG_Printf(DBG_CHN_TRACE
,"Skipping unknown entry %d %d %d\n", coff_sym
->StorageClass
,
1779 coff_sym
->SectionNumber
, naux
);
1783 * For now, skip past the aux entries.
1790 * OK, we now should have a list of files, and we should have a list
1791 * of entrypoints. We need to sort the entrypoints so that we are
1792 * able to tie the line numbers with the given functions within the
1795 if( coff_files
!= NULL
)
1797 for(j
=0; j
< nfiles
; j
++)
1799 if( coff_files
[j
].entries
!= NULL
)
1801 qsort(coff_files
[j
].entries
, coff_files
[j
].neps
,
1802 sizeof(struct name_hash
*), DEBUG_cmp_sym
);
1807 * Now pick apart the line number tables, and attach the entries
1808 * to the given functions.
1810 for(j
=0; j
< nfiles
; j
++)
1813 if( coff_files
[j
].neps
!= 0 )
1814 for(k
=0; k
< coff_files
[j
].linecnt
; k
++)
1817 * Another monstrosity caused by the fact that we are using
1818 * a 6 byte structure, and gcc wants to pad structures to 4 byte
1819 * boundaries. Otherwise we could just index into an array.
1821 linepnt
= (struct CoffLinenum
*)
1822 ((unsigned int) coff_linetab
+
1823 6*(coff_files
[j
].linetab_offset
+ k
));
1825 * If we have spilled onto the next entrypoint, then
1826 * bump the counter..
1830 if (i
+1 >= coff_files
[j
].neps
) break;
1831 DEBUG_GetSymbolAddr(coff_files
[j
].entries
[i
+1], &new_value
.addr
);
1832 if( (((unsigned int)module
->load_addr
+
1833 linepnt
->VirtualAddr
) >= new_value
.addr
.off
) )
1840 * Add the line number. This is always relative to the
1841 * start of the function, so we need to subtract that offset
1844 DEBUG_GetSymbolAddr(coff_files
[j
].entries
[i
], &new_value
.addr
);
1845 DEBUG_AddLineNumber(coff_files
[j
].entries
[i
],
1847 (unsigned int) module
->load_addr
1848 + linepnt
->VirtualAddr
1849 - new_value
.addr
.off
);
1856 if( coff_files
!= NULL
)
1858 for(j
=0; j
< nfiles
; j
++)
1860 if( coff_files
[j
].entries
!= NULL
)
1862 DBG_free(coff_files
[j
].entries
);
1865 DBG_free(coff_files
);
1873 * Process a codeview line number table. Digestify the thing so that
1874 * we can easily reference the thing when we process the rest of
1877 static struct codeview_linetab_hdr
*
1878 DEBUG_SnarfLinetab(char * linetab
,
1882 char filename
[PATH_MAX
];
1883 unsigned int * filetab
;
1887 struct codeview_linetab_hdr
* lt_hdr
;
1888 unsigned int * lt_ptr
;
1892 union any_size pnt2
;
1893 struct startend
* start
;
1897 * Now get the important bits.
1903 filetab
= (unsigned int *) pnt
.c
;
1906 * Now count up the number of segments in the file.
1909 for(i
=0; i
<nfile
; i
++)
1911 pnt2
.c
= linetab
+ filetab
[i
];
1916 * Next allocate the header we will be returning.
1917 * There is one header for each segment, so that we can reach in
1918 * and pull bits as required.
1920 lt_hdr
= (struct codeview_linetab_hdr
*)
1921 DBG_alloc((nseg
+ 1) * sizeof(*lt_hdr
));
1922 if( lt_hdr
== NULL
)
1927 memset(lt_hdr
, 0, sizeof(*lt_hdr
) * (nseg
+1));
1930 * Now fill the header we will be returning, one for each segment.
1931 * Note that this will basically just contain pointers into the existing
1932 * line table, and we do not actually copy any additional information
1933 * or allocate any additional memory.
1937 for(i
=0; i
<nfile
; i
++)
1940 * Get the pointer into the segment information.
1942 pnt2
.c
= linetab
+ filetab
[i
];
1943 file_segcount
= *pnt2
.s
;
1946 lt_ptr
= (unsigned int *) pnt2
.c
;
1947 start
= (struct startend
*) (lt_ptr
+ file_segcount
);
1950 * Now snarf the filename for all of the segments for this file.
1952 fn
= (unsigned char *) (start
+ file_segcount
);
1953 memset(filename
, 0, sizeof(filename
));
1954 memcpy(filename
, fn
+ 1, *fn
);
1955 fn
= DBG_strdup(filename
);
1957 for(k
= 0; k
< file_segcount
; k
++, this_seg
++)
1959 pnt2
.c
= linetab
+ lt_ptr
[k
];
1960 lt_hdr
[this_seg
].start
= start
[k
].start
;
1961 lt_hdr
[this_seg
].end
= start
[k
].end
;
1962 lt_hdr
[this_seg
].sourcefile
= fn
;
1963 lt_hdr
[this_seg
].segno
= *pnt2
.s
++;
1964 lt_hdr
[this_seg
].nline
= *pnt2
.s
++;
1965 lt_hdr
[this_seg
].offtab
= pnt2
.ui
;
1966 lt_hdr
[this_seg
].linetab
= (unsigned short *)
1967 (pnt2
.ui
+ lt_hdr
[this_seg
].nline
);
1978 DEBUG_SnarfCodeView( DBG_MODULE
* module
,
1981 struct codeview_linetab_hdr
* linetab
)
1983 struct name_hash
* curr_func
= NULL
;
1984 struct wine_locals
* curr_sym
= NULL
;
1988 DBG_VALUE new_value
;
1991 IMAGE_SECTION_HEADER
* sectp
;
1992 union codeview_symbol
* sym
;
1993 char symname
[PATH_MAX
];
1994 struct name_hash
* thunk_sym
= NULL
;
1997 nsect
= MSC_INFO(module
)->nsect
;
1998 sectp
= DBG_alloc(sizeof(*sectp
) * nsect
);
2000 !DEBUG_READ_MEM_VERBOSE((char *)module
->load_addr
+ MSC_INFO(module
)->sect_ofs
,
2001 sectp
, sizeof(*sectp
) * nsect
))
2005 * Loop over the different types of records and whenever we
2006 * find something we are interested in, record it and move on.
2008 while( ptr
.c
- cv_data
< size
)
2010 sym
= (union codeview_symbol
*) ptr
.c
;
2012 if( sym
->generic
.len
- sizeof(int) == (ptr
.c
- cv_data
) )
2015 * This happens when we have indirect symbols that VC++ 4.2
2016 * sometimes uses when there isn't a line number table.
2017 * We ignore it - we will process and enter all of the
2018 * symbols in the global symbol table anyways, so there
2019 * isn't much point in keeping track of all of this crap.
2024 memset(symname
, 0, sizeof(symname
));
2025 switch(sym
->generic
.id
)
2031 * First, a couple of sanity checks.
2033 if( sym
->data
.namelen
== 0 )
2038 if( sym
->data
.seg
== 0 || sym
->data
.seg
> nsect
)
2044 * Global and local data symbols. We don't associate these
2045 * with any given source file.
2048 memcpy(symname
, sym
->data
.name
, sym
->data
.namelen
);
2049 new_value
.addr
.seg
= 0;
2050 new_value
.type
= DEBUG_GetCVType(sym
->data
.symtype
);
2051 new_value
.addr
.off
= (unsigned int) module
->load_addr
+
2052 sectp
[sym
->data
.seg
- 1].VirtualAddress
+
2054 new_value
.cookie
= DV_TARGET
;
2055 DEBUG_AddSymbol( symname
, &new_value
, NULL
, SYM_WIN32
| SYM_DATA
);
2061 * First, a couple of sanity checks.
2063 if( sym
->data32
.namelen
== 0 )
2068 if( sym
->data32
.seg
== 0 || sym
->data32
.seg
> nsect
)
2074 * Global and local data symbols. We don't associate these
2075 * with any given source file.
2078 memcpy(symname
, sym
->data32
.name
, sym
->data32
.namelen
);
2079 new_value
.addr
.seg
= 0;
2080 new_value
.type
= DEBUG_GetCVType(sym
->data32
.symtype
);
2081 new_value
.addr
.off
= (unsigned int) module
->load_addr
+
2082 sectp
[sym
->data32
.seg
- 1].VirtualAddress
+
2084 new_value
.cookie
= DV_TARGET
;
2085 DEBUG_AddSymbol( symname
, &new_value
, NULL
, SYM_WIN32
| SYM_DATA
);
2089 * Sort of like a global function, but it just points
2090 * to a thunk, which is a stupid name for what amounts to
2091 * a PLT slot in the normal jargon that everyone else uses.
2093 memcpy(symname
, sym
->thunk
.name
, sym
->thunk
.namelen
);
2094 new_value
.addr
.seg
= 0;
2095 new_value
.type
= NULL
;
2096 new_value
.addr
.off
= (unsigned int) module
->load_addr
+
2097 sectp
[sym
->thunk
.segment
- 1].VirtualAddress
+
2099 new_value
.cookie
= DV_TARGET
;
2100 thunk_sym
= DEBUG_AddSymbol( symname
, &new_value
, NULL
,
2101 SYM_WIN32
| SYM_FUNC
);
2102 DEBUG_SetSymbolSize(thunk_sym
, sym
->thunk
.thunk_len
);
2107 * Global and static functions.
2109 memcpy(symname
, sym
->proc
.name
, sym
->proc
.namelen
);
2110 new_value
.addr
.seg
= 0;
2111 new_value
.type
= DEBUG_GetCVType(sym
->proc
.proctype
);
2112 new_value
.addr
.off
= (unsigned int) module
->load_addr
+
2113 sectp
[sym
->proc
.segment
- 1].VirtualAddress
+
2115 new_value
.cookie
= DV_TARGET
;
2117 * See if we can find a segment that this goes with. If so,
2118 * it means that we also may have line number information
2119 * for this function.
2121 for(i
=0; linetab
&& linetab
[i
].linetab
!= NULL
; i
++)
2123 if( ((unsigned int) module
->load_addr
2124 + sectp
[linetab
[i
].segno
- 1].VirtualAddress
2125 + linetab
[i
].start
<= new_value
.addr
.off
)
2126 && ((unsigned int) module
->load_addr
2127 + sectp
[linetab
[i
].segno
- 1].VirtualAddress
2128 + linetab
[i
].end
> new_value
.addr
.off
) )
2134 DEBUG_Normalize(curr_func
);
2135 if( !linetab
|| linetab
[i
].linetab
== NULL
)
2137 curr_func
= DEBUG_AddSymbol( symname
, &new_value
, NULL
,
2138 SYM_WIN32
| SYM_FUNC
);
2143 * First, create the entry. Then dig through the linetab
2144 * and add whatever line numbers are appropriate for this
2147 curr_func
= DEBUG_AddSymbol( symname
, &new_value
,
2148 linetab
[i
].sourcefile
,
2149 SYM_WIN32
| SYM_FUNC
);
2150 for(j
=0; j
< linetab
[i
].nline
; j
++)
2152 if( linetab
[i
].offtab
[j
] >= sym
->proc
.offset
2153 && linetab
[i
].offtab
[j
] < sym
->proc
.offset
2154 + sym
->proc
.proc_len
)
2156 DEBUG_AddLineNumber(curr_func
, linetab
[i
].linetab
[j
],
2157 linetab
[i
].offtab
[j
] - sym
->proc
.offset
);
2164 * Add information about where we should set breakpoints
2167 DEBUG_SetSymbolBPOff(curr_func
, sym
->proc
.debug_start
);
2168 DEBUG_SetSymbolSize(curr_func
, sym
->proc
.proc_len
);
2173 * Global and static functions.
2175 memcpy(symname
, sym
->proc32
.name
, sym
->proc32
.namelen
);
2176 new_value
.addr
.seg
= 0;
2177 new_value
.type
= DEBUG_GetCVType(sym
->proc32
.proctype
);
2178 new_value
.addr
.off
= (unsigned int) module
->load_addr
+
2179 sectp
[sym
->proc32
.segment
- 1].VirtualAddress
+
2181 new_value
.cookie
= DV_TARGET
;
2183 * See if we can find a segment that this goes with. If so,
2184 * it means that we also may have line number information
2185 * for this function.
2187 for(i
=0; linetab
&& linetab
[i
].linetab
!= NULL
; i
++)
2189 if( ((unsigned int) module
->load_addr
2190 + sectp
[linetab
[i
].segno
- 1].VirtualAddress
2191 + linetab
[i
].start
<= new_value
.addr
.off
)
2192 && ((unsigned int) module
->load_addr
2193 + sectp
[linetab
[i
].segno
- 1].VirtualAddress
2194 + linetab
[i
].end
> new_value
.addr
.off
) )
2200 DEBUG_Normalize(curr_func
);
2201 if( !linetab
|| linetab
[i
].linetab
== NULL
)
2203 curr_func
= DEBUG_AddSymbol( symname
, &new_value
, NULL
,
2204 SYM_WIN32
| SYM_FUNC
);
2209 * First, create the entry. Then dig through the linetab
2210 * and add whatever line numbers are appropriate for this
2213 curr_func
= DEBUG_AddSymbol( symname
, &new_value
,
2214 linetab
[i
].sourcefile
,
2215 SYM_WIN32
| SYM_FUNC
);
2216 for(j
=0; j
< linetab
[i
].nline
; j
++)
2218 if( linetab
[i
].offtab
[j
] >= sym
->proc32
.offset
2219 && linetab
[i
].offtab
[j
] < sym
->proc32
.offset
2220 + sym
->proc32
.proc_len
)
2222 DEBUG_AddLineNumber(curr_func
, linetab
[i
].linetab
[j
],
2223 linetab
[i
].offtab
[j
] - sym
->proc32
.offset
);
2230 * Add information about where we should set breakpoints
2233 DEBUG_SetSymbolBPOff(curr_func
, sym
->proc32
.debug_start
);
2234 DEBUG_SetSymbolSize(curr_func
, sym
->proc32
.proc_len
);
2238 * Function parameters and stack variables.
2240 memcpy(symname
, sym
->stack
.name
, sym
->stack
.namelen
);
2241 curr_sym
= DEBUG_AddLocal(curr_func
,
2247 DEBUG_SetLocalSymbolType(curr_sym
, DEBUG_GetCVType(sym
->stack
.symtype
));
2252 * Function parameters and stack variables.
2254 memcpy(symname
, sym
->stack32
.name
, sym
->stack32
.namelen
);
2255 curr_sym
= DEBUG_AddLocal(curr_func
,
2257 sym
->stack32
.offset
,
2261 DEBUG_SetLocalSymbolType(curr_sym
, DEBUG_GetCVType(sym
->stack32
.symtype
));
2269 * Adjust pointer to point to next entry, rounding up to a word
2270 * boundary. MS preserving alignment? Stranger things have
2273 if( sym
->generic
.id
== S_PROCREF
2274 || sym
->generic
.id
== S_DATAREF
2275 || sym
->generic
.id
== S_LPROCREF
)
2277 len
= (sym
->generic
.len
+ 3) & ~3;
2278 len
+= ptr
.c
[16] + 1;
2279 ptr
.c
+= (len
+ 3) & ~3;
2283 ptr
.c
+= (sym
->generic
.len
+ 3) & ~3;
2287 if( linetab
!= NULL
)
2298 * Process PDB file which contains debug information.
2302 typedef struct _PDB_FILE
2307 } PDB_FILE
, *PPDB_FILE
;
2309 typedef struct _PDB_HEADER
2317 WORD toc_block
[ 1 ];
2319 } PDB_HEADER
, *PPDB_HEADER
;
2321 typedef struct _PDB_TOC
2326 } PDB_TOC
, *PPDB_TOC
;
2328 typedef struct _PDB_ROOT
2331 DWORD TimeDateStamp
;
2336 } PDB_ROOT
, *PPDB_ROOT
;
2338 typedef struct _PDB_TYPES_OLD
2347 } PDB_TYPES_OLD
, *PPDB_TYPES_OLD
;
2349 typedef struct _PDB_TYPES
2362 DWORD search_offset
;
2364 DWORD unknown_offset
;
2367 } PDB_TYPES
, *PPDB_TYPES
;
2369 typedef struct _PDB_SYMBOL_RANGE
2375 DWORD characteristics
;
2379 } PDB_SYMBOL_RANGE
, *PPDB_SYMBOL_RANGE
;
2381 typedef struct _PDB_SYMBOL_RANGE_EX
2387 DWORD characteristics
;
2393 } PDB_SYMBOL_RANGE_EX
, *PPDB_SYMBOL_RANGE_EX
;
2395 typedef struct _PDB_SYMBOL_FILE
2398 PDB_SYMBOL_RANGE range
;
2408 } PDB_SYMBOL_FILE
, *PPDB_SYMBOL_FILE
;
2410 typedef struct _PDB_SYMBOL_FILE_EX
2413 PDB_SYMBOL_RANGE_EX range
;
2421 DWORD reserved
[ 2 ];
2424 } PDB_SYMBOL_FILE_EX
, *PPDB_SYMBOL_FILE_EX
;
2426 typedef struct _PDB_SYMBOL_SOURCE
2432 } PDB_SYMBOL_SOURCE
, *PPDB_SYMBOL_SOURCE
;
2434 typedef struct _PDB_SYMBOL_IMPORT
2438 DWORD TimeDateStamp
;
2442 } PDB_SYMBOL_IMPORT
, *PPDB_SYMBOL_IMPORT
;
2444 typedef struct _PDB_SYMBOLS_OLD
2453 DWORD srcmodule_size
;
2455 } PDB_SYMBOLS_OLD
, *PPDB_SYMBOLS_OLD
;
2457 typedef struct _PDB_SYMBOLS
2461 DWORD extended_format
;
2468 DWORD srcmodule_size
;
2469 DWORD pdbimport_size
;
2472 } PDB_SYMBOLS
, *PPDB_SYMBOLS
;
2476 static void *pdb_read( LPBYTE image
, WORD
*block_list
, int size
)
2478 PPDB_HEADER pdb
= (PPDB_HEADER
)image
;
2482 if ( !size
) return NULL
;
2484 nBlocks
= (size
+ pdb
->blocksize
-1) / pdb
->blocksize
;
2485 buffer
= DBG_alloc( nBlocks
* pdb
->blocksize
);
2487 for ( i
= 0; i
< nBlocks
; i
++ )
2488 memcpy( buffer
+ i
*pdb
->blocksize
,
2489 image
+ block_list
[i
]*pdb
->blocksize
, pdb
->blocksize
);
2494 static void *pdb_read_file( LPBYTE image
, PPDB_TOC toc
, int fileNr
)
2496 PPDB_HEADER pdb
= (PPDB_HEADER
)image
;
2500 if ( !toc
|| fileNr
>= toc
->nFiles
)
2503 block_list
= (WORD
*) &toc
->file
[ toc
->nFiles
];
2504 for ( i
= 0; i
< fileNr
; i
++ )
2505 block_list
+= (toc
->file
[i
].size
+ pdb
->blocksize
-1) / pdb
->blocksize
;
2507 return pdb_read( image
, block_list
, toc
->file
[fileNr
].size
);
2510 static void pdb_free( void *buffer
)
2515 static void pdb_convert_types_header( PDB_TYPES
*types
, char *image
)
2517 memset( types
, 0, sizeof(PDB_TYPES
) );
2518 if ( !image
) return;
2520 if ( *(DWORD
*)image
< 19960000 ) /* FIXME: correct version? */
2522 /* Old version of the types record header */
2523 PDB_TYPES_OLD
*old
= (PDB_TYPES_OLD
*)image
;
2524 types
->version
= old
->version
;
2525 types
->type_offset
= sizeof(PDB_TYPES_OLD
);
2526 types
->type_size
= old
->type_size
;
2527 types
->first_index
= old
->first_index
;
2528 types
->last_index
= old
->last_index
;
2529 types
->file
= old
->file
;
2533 /* New version of the types record header */
2534 *types
= *(PDB_TYPES
*)image
;
2538 static void pdb_convert_symbols_header( PDB_SYMBOLS
*symbols
,
2539 int *header_size
, char *image
)
2541 memset( symbols
, 0, sizeof(PDB_SYMBOLS
) );
2542 if ( !image
) return;
2544 if ( *(DWORD
*)image
!= 0xffffffff )
2546 /* Old version of the symbols record header */
2547 PDB_SYMBOLS_OLD
*old
= (PDB_SYMBOLS_OLD
*)image
;
2548 symbols
->version
= 0;
2549 symbols
->extended_format
= 0;
2550 symbols
->module_size
= old
->module_size
;
2551 symbols
->offset_size
= old
->offset_size
;
2552 symbols
->hash_size
= old
->hash_size
;
2553 symbols
->srcmodule_size
= old
->srcmodule_size
;
2554 symbols
->pdbimport_size
= 0;
2555 symbols
->hash1_file
= old
->hash1_file
;
2556 symbols
->hash2_file
= old
->hash2_file
;
2557 symbols
->gsym_file
= old
->gsym_file
;
2559 *header_size
= sizeof(PDB_SYMBOLS_OLD
);
2563 /* New version of the symbols record header */
2564 *symbols
= *(PDB_SYMBOLS
*)image
;
2566 *header_size
= sizeof(PDB_SYMBOLS
);
2570 static int DEBUG_ProcessPDBFile( DBG_MODULE
* module
, const char *full_filename
)
2574 PDB_HEADER
*pdb
= NULL
;
2575 PDB_TOC
*toc
= NULL
;
2576 PDB_ROOT
*root
= NULL
;
2577 char *types_image
= NULL
;
2578 char *symbols_image
= NULL
;
2580 PDB_SYMBOLS symbols
;
2581 int header_size
= 0;
2582 char *modimage
, *file
;
2586 * Open and map() .PDB file
2588 if ((image
= DEBUG_MapDebugInfoFile(full_filename
, 0, 0, &hFile
, &hMap
)) == NULL
) {
2589 DEBUG_Printf( DBG_CHN_ERR
, "-Unable to peruse .PDB file %s\n", full_filename
);
2594 * Read in TOC and well-known files
2597 pdb
= (PPDB_HEADER
)image
;
2598 toc
= pdb_read( image
, pdb
->toc_block
, pdb
->toc
.size
);
2599 root
= pdb_read_file( image
, toc
, 1 );
2600 types_image
= pdb_read_file( image
, toc
, 2 );
2601 symbols_image
= pdb_read_file( image
, toc
, 3 );
2603 pdb_convert_types_header( &types
, types_image
);
2604 pdb_convert_symbols_header( &symbols
, &header_size
, symbols_image
);
2607 * Check for unknown versions
2610 switch ( root
->version
)
2612 case 19950623: /* VC 4.0 */
2614 case 19960307: /* VC 5.0 */
2615 case 19970604: /* VC 6.0 */
2618 DEBUG_Printf( DBG_CHN_ERR
, "-Unknown root block version %ld\n", root
->version
);
2621 switch ( types
.version
)
2623 case 19950410: /* VC 4.0 */
2625 case 19961031: /* VC 5.0 / 6.0 */
2628 DEBUG_Printf( DBG_CHN_ERR
, "-Unknown type info version %ld\n", types
.version
);
2631 switch ( symbols
.version
)
2633 case 0: /* VC 4.0 */
2634 case 19960307: /* VC 5.0 */
2635 case 19970606: /* VC 6.0 */
2638 DEBUG_Printf( DBG_CHN_ERR
, "-Unknown symbol info version %ld\n", symbols
.version
);
2643 * Check .PDB time stamp
2646 if ( root
->TimeDateStamp
2647 != ((struct CodeViewDebug
*)MSC_INFO(module
)->dbg_info
)->cv_timestamp
)
2649 DEBUG_Printf(DBG_CHN_ERR
, "-Wrong time stamp of .PDB file %s\n", full_filename
);
2657 DEBUG_ParseTypeTable( types_image
+ types
.type_offset
, types
.type_size
);
2660 * Read type-server .PDB imports
2663 if ( symbols
.pdbimport_size
)
2666 DEBUG_Printf(DBG_CHN_ERR
, "-Type server .PDB imports ignored!\n" );
2670 * Read global symbol table
2673 modimage
= pdb_read_file( image
, toc
, symbols
.gsym_file
);
2676 DEBUG_SnarfCodeView( module
, modimage
,
2677 toc
->file
[symbols
.gsym_file
].size
, NULL
);
2678 pdb_free( modimage
);
2682 * Read per-module symbol / linenumber tables
2685 file
= symbols_image
+ header_size
;
2686 while ( file
- symbols_image
< header_size
+ symbols
.module_size
)
2688 int file_nr
, file_index
, symbol_size
, lineno_size
;
2691 if ( !symbols
.extended_format
)
2693 PDB_SYMBOL_FILE
*sym_file
= (PDB_SYMBOL_FILE
*) file
;
2694 file_nr
= sym_file
->file
;
2695 file_name
= sym_file
->filename
;
2696 file_index
= sym_file
->range
.index
;
2697 symbol_size
= sym_file
->symbol_size
;
2698 lineno_size
= sym_file
->lineno_size
;
2702 PDB_SYMBOL_FILE_EX
*sym_file
= (PDB_SYMBOL_FILE_EX
*) file
;
2703 file_nr
= sym_file
->file
;
2704 file_name
= sym_file
->filename
;
2705 file_index
= sym_file
->range
.index
;
2706 symbol_size
= sym_file
->symbol_size
;
2707 lineno_size
= sym_file
->lineno_size
;
2710 modimage
= pdb_read_file( image
, toc
, file_nr
);
2713 struct codeview_linetab_hdr
*linetab
= NULL
;
2716 linetab
= DEBUG_SnarfLinetab( modimage
+ symbol_size
, lineno_size
);
2719 DEBUG_SnarfCodeView( module
, modimage
+ sizeof(DWORD
),
2720 symbol_size
- sizeof(DWORD
), linetab
);
2722 pdb_free( modimage
);
2725 file_name
+= strlen(file_name
) + 1;
2726 file
= (char *)( (DWORD
)(file_name
+ strlen(file_name
) + 1 + 3) & ~3 );
2736 if ( symbols_image
) pdb_free( symbols_image
);
2737 if ( types_image
) pdb_free( types_image
);
2738 if ( root
) pdb_free( root
);
2739 if ( toc
) pdb_free( toc
);
2741 DEBUG_UnmapDebugInfoFile(hFile
, hMap
, image
);
2748 * Process DBG file which contains debug information.
2752 DEBUG_ProcessDBGFile(DBG_MODULE
* module
, const char* filename
)
2757 struct CV4_DirHead
* codeview_dir
;
2758 struct CV4_DirEnt
* codeview_dent
;
2759 PIMAGE_DEBUG_DIRECTORY dbghdr
;
2763 struct codeview_linetab_hdr
* linetab
;
2765 PIMAGE_SEPARATE_DEBUG_HEADER pdbg
= NULL
;
2766 IMAGE_SECTION_HEADER
* sectp
;
2768 if ((addr
= DEBUG_MapDebugInfoFile(filename
, 0, 0, &hFile
, &hMap
)) == NULL
) {
2769 DEBUG_Printf(DBG_CHN_ERR
, "-Unable to peruse .DBG file %s\n", filename
);
2773 pdbg
= (PIMAGE_SEPARATE_DEBUG_HEADER
) addr
;
2775 if( pdbg
->TimeDateStamp
!= MSC_INFO(module
)->dbgdir
.TimeDateStamp
)
2777 DEBUG_Printf(DBG_CHN_ERR
, "Warning - %s has incorrect internal timestamp\n",
2781 Well, sometimes this happens to DBG files which ARE REALLY the right .DBG
2782 files but nonetheless this check fails. Anyway, WINDBG (debugger for
2783 Windows by Microsoft) loads debug symbols which have incorrect timestamps.
2787 DEBUG_Printf(DBG_CHN_MESG
, "Processing symbols from %s...\n", filename
);
2789 dbghdr
= (PIMAGE_DEBUG_DIRECTORY
) ( addr
+ sizeof(*pdbg
)
2790 + pdbg
->NumberOfSections
* sizeof(IMAGE_SECTION_HEADER
)
2791 + pdbg
->ExportedNamesSize
);
2793 sectp
= (PIMAGE_SECTION_HEADER
) ((char *) pdbg
+ sizeof(*pdbg
));
2794 nsect
= pdbg
->NumberOfSections
;
2796 for( i
=0; i
< pdbg
->DebugDirectorySize
/ sizeof(*pdbg
); i
++, dbghdr
++ )
2798 switch(dbghdr
->Type
)
2800 case IMAGE_DEBUG_TYPE_COFF
:
2802 * Dummy up a deferred debug header to handle the
2803 * COFF stuff embedded within the DBG file.
2805 memset((char *) &module2
, 0, sizeof(module2
));
2806 MSC_INFO(&module2
)->dbg_info
= (addr
+ dbghdr
->PointerToRawData
);
2807 MSC_INFO(&module2
)->dbg_size
= dbghdr
->SizeOfData
;
2808 module2
.load_addr
= module
->load_addr
;
2810 DEBUG_ProcessCoff(&module2
);
2812 case IMAGE_DEBUG_TYPE_CODEVIEW
:
2814 * This is the older format by which codeview stuff is
2815 * stored, known as the 'NB09' format. Newer executables
2816 * and dlls created by VC++ use PDB files instead, which
2817 * have lots of internal similarities, but the overall
2818 * format and structure is quite different.
2820 codeview
= (addr
+ dbghdr
->PointerToRawData
);
2823 * The first thing in the codeview section should be
2824 * an 'NB09' identifier. As a sanity check, make sure
2827 if( *((unsigned int*) codeview
) != 0x3930424e )
2833 * Next we need to find the directory. This is easy too.
2835 codeview_dir
= (struct CV4_DirHead
*)
2836 (codeview
+ ((unsigned int*) codeview
)[1]);
2839 * Some more sanity checks. Make sure that everything
2840 * is as we expect it.
2842 if( codeview_dir
->next_offset
!= 0
2843 || codeview_dir
->dhsize
!= sizeof(*codeview_dir
)
2844 || codeview_dir
->desize
!= sizeof(*codeview_dent
) )
2848 codeview_dent
= (struct CV4_DirEnt
*) (codeview_dir
+ 1);
2850 for(j
=0; j
< codeview_dir
->ndir
; j
++, codeview_dent
++)
2852 if( codeview_dent
->subsect_number
== sstAlignSym
)
2855 * Check the previous entry. If it is a
2856 * sstSrcModule, it contains the line number
2857 * info for this file.
2860 if( codeview_dent
[1].module_number
== codeview_dent
[0].module_number
2861 && codeview_dent
[1].subsect_number
== sstSrcModule
)
2863 linetab
= DEBUG_SnarfLinetab(
2864 codeview
+ codeview_dent
[1].offset
,
2865 codeview_dent
[1].size
);
2868 if( codeview_dent
[-1].module_number
== codeview_dent
[0].module_number
2869 && codeview_dent
[-1].subsect_number
== sstSrcModule
)
2871 linetab
= DEBUG_SnarfLinetab(
2872 codeview
+ codeview_dent
[-1].offset
,
2873 codeview_dent
[-1].size
);
2876 * Now process the CV stuff.
2878 DEBUG_SnarfCodeView(module
,
2879 codeview
+ codeview_dent
->offset
+ sizeof(DWORD
),
2880 codeview_dent
->size
- sizeof(DWORD
),
2892 DEBUG_UnmapDebugInfoFile(hFile
, hMap
, addr
);
2898 DEBUG_ProcessMSCDebugInfo(DBG_MODULE
* module
)
2900 struct CodeViewDebug
* cvd
;
2901 struct MiscDebug
* misc
;
2905 switch (MSC_INFO(module
)->dbgdir
.Type
)
2907 case IMAGE_DEBUG_TYPE_COFF
:
2909 * Standard COFF debug information that VC++ adds when you
2910 * use /debugtype:both with the linker.
2912 DEBUG_Printf(DBG_CHN_TRACE
, "Processing COFF symbols...\n");
2913 sts
= DEBUG_ProcessCoff(module
);
2915 case IMAGE_DEBUG_TYPE_CODEVIEW
:
2917 * This is a pointer to a PDB file of some sort.
2919 cvd
= (struct CodeViewDebug
*) MSC_INFO(module
)->dbg_info
;
2921 if( strcmp(cvd
->cv_nbtype
, "NB10") != 0 )
2924 * Whatever this is, we don't know how to deal with
2930 sts
= DEBUG_ProcessPDBFile(module
, cvd
->cv_name
);
2931 DEBUG_Printf(DBG_CHN_TRACE
, "Processing PDB file %s\n", cvd
->cv_name
);
2933 case IMAGE_DEBUG_TYPE_MISC
:
2935 * A pointer to a .DBG file of some sort. These files
2936 * can contain either CV4 or COFF information. Open
2937 * the file, and try to do the right thing with it.
2939 misc
= (struct MiscDebug
*) MSC_INFO(module
)->dbg_info
;
2941 filename
= strrchr((char *) &misc
->Data
, '.');
2944 * Ignore the file if it doesn't have a .DBG extension.
2946 if( (filename
== NULL
)
2947 || ( (strcmp(filename
, ".dbg") != 0)
2948 && (strcmp(filename
, ".DBG") != 0)) )
2954 filename
= (char *) &misc
->Data
;
2957 * Do the dirty deed...
2959 sts
= DEBUG_ProcessDBGFile(module
, filename
);
2964 * We should never get here...
2969 module
->status
= (sts
) ? DM_STATUS_LOADED
: DM_STATUS_ERROR
;