Implementation of custom dialog messages and notifications.
[wine.git] / debugger / msc.c
bloba998709f0a4194892e6856095f35866639448cda
1 /*
2 * File msc.c - read VC++ debug information from COFF and eventually
3 * from PDB files.
5 * Copyright (C) 1996, Eric Youngdale.
7 * Note - this handles reading debug information for 32 bit applications
8 * that run under Windows-NT for example. I doubt that this would work well
9 * for 16 bit applications, but I don't think it really matters since the
10 * file format is different, and we should never get in here in such cases.
12 * TODO:
13 * Get 16 bit CV stuff working.
14 * Add symbol size to internal symbol table.
17 #include "config.h"
18 #include <stdio.h>
19 #include <stdlib.h>
21 #include <sys/types.h>
22 #ifdef HAVE_SYS_MMAN_H
23 #include <sys/mman.h>
24 #endif
25 #include <fcntl.h>
26 #include <sys/stat.h>
27 #include <limits.h>
28 #include <string.h>
29 #include <unistd.h>
30 #ifndef PATH_MAX
31 #define PATH_MAX _MAX_PATH
32 #endif
33 #include "debugger.h"
34 #include "neexe.h"
35 #include "peexe.h"
36 #include "file.h"
39 *dbg_filename must be at least MAX_PATHNAME_LEN bytes in size
41 static void LocateDebugInfoFile(char *filename, char *dbg_filename)
43 char *str1 = DBG_alloc(MAX_PATHNAME_LEN*10);
44 char *str2 = DBG_alloc(MAX_PATHNAME_LEN);
45 char *file;
46 char *name_part;
47 DOS_FULL_NAME fullname;
49 file = strrchr(filename, '\\');
50 if( file == NULL ) file = filename; else file++;
52 if (GetEnvironmentVariableA("_NT_SYMBOL_PATH", str1, MAX_PATHNAME_LEN))
53 if (SearchPathA(str1, file, NULL, MAX_PATHNAME_LEN*10, str2, &name_part))
54 goto ok;
55 if (GetEnvironmentVariableA("_NT_ALT_SYMBOL_PATH", str1, MAX_PATHNAME_LEN))
56 if (SearchPathA(str1, file, NULL, MAX_PATHNAME_LEN*10, str2, &name_part))
57 goto ok;
58 if (SearchPathA(NULL, file, NULL, MAX_PATHNAME_LEN*10, str2, &name_part))
59 goto ok;
60 else
62 quit:
63 memcpy(dbg_filename, filename, MAX_PATHNAME_LEN);
64 DBG_free(str1);
65 DBG_free(str2);
66 return;
68 ok:
69 if (DOSFS_GetFullName(str2, TRUE, &fullname))
70 memcpy(dbg_filename, fullname.long_name, MAX_PATHNAME_LEN);
71 else
72 goto quit;
73 DBG_free(str1);
74 DBG_free(str2);
75 return;
78 * This is an index we use to keep track of the debug information
79 * when we have multiple sources. We use the same database to also
80 * allow us to do an 'info shared' type of deal, and we use the index
81 * to eliminate duplicates.
83 static int DEBUG_next_index = 0;
85 union any_size
87 char * c;
88 short * s;
89 int * i;
90 unsigned int * ui;
94 * This is a convenience structure used to map portions of the
95 * line number table.
97 struct startend
99 unsigned int start;
100 unsigned int end;
104 * This is how we reference the various record types.
106 union codeview_symbol
108 struct
110 short int len;
111 short int id;
112 } generic;
114 struct
116 short int len;
117 short int id;
118 unsigned int offset;
119 unsigned short seg;
120 unsigned short symtype;
121 unsigned char namelen;
122 unsigned char name[1];
123 } data;
125 struct
127 short int len;
128 short int id;
129 unsigned int pparent;
130 unsigned int pend;
131 unsigned int next;
132 unsigned int offset;
133 unsigned short segment;
134 unsigned short thunk_len;
135 unsigned char thtype;
136 unsigned char namelen;
137 unsigned char name[1];
138 } thunk;
139 struct
141 short int len;
142 short int id;
143 unsigned int pparent;
144 unsigned int pend;
145 unsigned int next;
146 unsigned int proc_len;
147 unsigned int debug_start;
148 unsigned int debug_end;
149 unsigned int offset;
150 unsigned short segment;
151 unsigned short proctype;
152 unsigned char flags;
153 unsigned char namelen;
154 unsigned char name[1];
155 } proc;
156 struct
158 short int len; /* Total length of this entry */
159 short int id; /* Always S_BPREL32 */
160 unsigned int offset; /* Stack offset relative to BP */
161 unsigned short symtype;
162 unsigned char namelen;
163 unsigned char name[1];
164 } stack;
167 union codeview_type
169 struct
171 short int len;
172 short int id;
173 } generic;
175 struct
177 short int len;
178 short int id;
179 short int attribute;
180 short int datatype;
181 unsigned char variant[1];
182 } pointer;
184 struct
186 short int len;
187 short int id;
188 unsigned char nbits;
189 unsigned char bitoff;
190 unsigned short type;
191 } bitfield;
193 struct
195 short int len;
196 short int id;
197 short int elemtype;
198 short int idxtype;
199 unsigned char arrlen;
200 unsigned char namelen;
201 unsigned char name[1];
202 } array;
204 struct
206 short int len;
207 short int id;
208 short int n_element;
209 short int fieldlist;
210 short int property;
211 short int derived;
212 short int vshape;
213 unsigned short structlen;
214 unsigned char namelen;
215 unsigned char name[1];
216 } structure;
218 struct
220 short int len;
221 short int id;
222 short int count;
223 short int field;
224 short int property;
225 unsigned short un_len;
226 unsigned char namelen;
227 unsigned char name[1];
228 } t_union;
230 struct
232 short int len;
233 short int id;
234 short int count;
235 short int type;
236 short int field;
237 short int property;
238 unsigned char namelen;
239 unsigned char name[1];
240 } enumeration;
242 struct
244 short int id;
245 short int attribute;
246 unsigned short int value;
247 unsigned char namelen;
248 unsigned char name[1];
249 } enumerate;
251 struct
253 short int id;
254 short int type;
255 short int attribute;
256 unsigned short int offset;
257 unsigned char namelen;
258 unsigned char name[1];
259 } member;
261 struct
263 short int len;
264 short int id;
265 short int count;
266 short int type;
267 short int field;
268 short int property;
269 unsigned char namelen;
270 unsigned char name[1];
271 } fieldlist;
275 #define S_BPREL 0x200
276 #define S_LDATA 0x201
277 #define S_GDATA 0x202
278 #define S_PUB 0x203
279 #define S_LPROC 0x204
280 #define S_GPROC 0x205
281 #define S_THUNK 0x206
282 #define S_BLOCK 0x207
283 #define S_WITH 0x208
284 #define S_LABEL 0x209
286 #define S_PROCREF 0x400
287 #define S_DATAREF 0x401
288 #define S_ALIGN 0x402
289 #define S_UNKNOWN 0x403
292 * This covers the basic datatypes that VC++ seems to be using these days.
293 * 32 bit mode only. There are additional numbers for the pointers in 16
294 * bit mode. There are many other types listed in the documents, but these
295 * are apparently not used by the compiler, or represent pointer types
296 * that are not used.
298 #define T_NOTYPE 0x0000 /* Notype */
299 #define T_ABS 0x0001 /* Abs */
300 #define T_VOID 0x0003 /* Void */
301 #define T_CHAR 0x0010 /* signed char */
302 #define T_SHORT 0x0011 /* short */
303 #define T_LONG 0x0012 /* long */
304 #define T_QUAD 0x0013 /* long long */
305 #define T_UCHAR 0x0020 /* unsigned char */
306 #define T_USHORT 0x0021 /* unsigned short */
307 #define T_ULONG 0x0022 /* unsigned long */
308 #define T_UQUAD 0x0023 /* unsigned long long */
309 #define T_REAL32 0x0040 /* float */
310 #define T_REAL64 0x0041 /* double */
311 #define T_RCHAR 0x0070 /* real char */
312 #define T_WCHAR 0x0071 /* wide char */
313 #define T_INT4 0x0074 /* int */
314 #define T_UINT4 0x0075 /* unsigned int */
316 #define T_32PVOID 0x0403 /* 32 bit near pointer to void */
317 #define T_32PCHAR 0x0410 /* 16:32 near pointer to signed char */
318 #define T_32PSHORT 0x0411 /* 16:32 near pointer to short */
319 #define T_32PLONG 0x0412 /* 16:32 near pointer to int */
320 #define T_32PQUAD 0x0413 /* 16:32 near pointer to long long */
321 #define T_32PUCHAR 0x0420 /* 16:32 near pointer to unsigned char */
322 #define T_32PUSHORT 0x0421 /* 16:32 near pointer to unsigned short */
323 #define T_32PULONG 0x0422 /* 16:32 near pointer to unsigned int */
324 #define T_32PUQUAD 0x0423 /* 16:32 near pointer to long long */
325 #define T_32PREAL32 0x0440 /* 16:32 near pointer to float */
326 #define T_32PREAL64 0x0441 /* 16:32 near pointer to float */
327 #define T_32PRCHAR 0x0470 /* 16:32 near pointer to real char */
328 #define T_32PWCHAR 0x0471 /* 16:32 near pointer to real char */
329 #define T_32PINT4 0x0474 /* 16:32 near pointer to int */
330 #define T_32PUINT4 0x0475 /* 16:32 near pointer to unsigned int */
332 #define LF_MODIFIER 0x1
333 #define LF_POINTER 0x2
334 #define LF_ARRAY 0x3
335 #define LF_CLASS 0x4
336 #define LF_STRUCTURE 0x5
337 #define LF_UNION 0x6
338 #define LF_ENUMERATION 0x7
339 #define LF_PROCEDURE 0x8
340 #define LF_MFUNCTION 0x9
341 #define LF_VTSHAPE 0xa
342 #define LF_BARRAY 0xd
343 #define LF_DIMARRAY 0x11
344 #define LF_VFTPATH 0x12
346 #define LF_SKIP 0x200
347 #define LF_ARGLIST 0x201
348 #define LF_FIELDLIST 0x204
349 #define LF_DERIVED 0x205
350 #define LF_BITFIELD 0x206
352 #define LF_BCLASS 0x400
353 #define LF_VBCLASS 0x401
354 #define LF_IVBCLASS 0x402
355 #define LF_ENUMERATE 0x403
356 #define LF_FRIENDFCN 0x404
357 #define LF_INDEX 0x405
358 #define LF_MEMBER 0x406
359 #define LF_STMEMBER 0x407
360 #define LF_METHOD 0x408
361 #define LF_NESTEDTYPE 0x409
362 #define LF_VFUNCTAB 0x40a
363 #define LF_FRIENDCLS 0x40b
364 #define LF_ONEMETHOD 0x40c
365 #define LF_FUNCOFF 0x40d
367 #define MAX_BUILTIN_TYPES 0x480
368 static struct datatype * cv_basic_types[MAX_BUILTIN_TYPES];
369 static int num_cv_defined_types = 0;
370 static struct datatype **cv_defined_types = NULL;
373 * For the type CODEVIEW debug directory entries, the debug directory
374 * points to a structure like this. The cv_name field is the name
375 * of an external .PDB file.
377 struct CodeViewDebug
379 char cv_nbtype[8];
380 unsigned int cv_timestamp;
381 char cv_unknown[4];
382 char cv_name[1];
385 struct MiscDebug {
386 unsigned int DataType;
387 unsigned int Length;
388 char Unicode;
389 char Reserved[3];
390 char Data[1];
394 * This is the header that the COFF variety of debug header points to.
396 struct CoffDebug {
397 unsigned int N_Sym;
398 unsigned int SymbolOffset;
399 unsigned int N_Linenum;
400 unsigned int LinenumberOffset;
401 unsigned int Unused[4];
404 struct CoffLinenum {
405 unsigned int VirtualAddr;
406 unsigned short int Linenum;
409 struct CoffFiles {
410 unsigned int startaddr;
411 unsigned int endaddr;
412 char * filename;
413 int linetab_offset;
414 int linecnt;
415 struct name_hash **entries;
416 int neps;
417 int neps_alloc;
421 struct CoffSymbol {
422 union {
423 char ShortName[8];
424 struct {
425 unsigned int NotLong;
426 unsigned int StrTaboff;
427 } Name;
428 } N;
429 unsigned int Value;
430 short SectionNumber;
431 short Type;
432 char StorageClass;
433 unsigned char NumberOfAuxSymbols;
436 struct CoffAuxSection{
437 unsigned int Length;
438 unsigned short NumberOfRelocations;
439 unsigned short NumberOfLinenumbers;
440 unsigned int CheckSum;
441 short Number;
442 char Selection;
443 } Section;
446 * These two structures are used in the directory within a .DBG file
447 * to locate the individual important bits that we might want to see.
449 struct CV4_DirHead {
450 short unsigned int dhsize;
451 short unsigned int desize;
452 unsigned int ndir;
453 unsigned int next_offset;
454 unsigned int flags;
457 struct CV4_DirEnt {
458 short unsigned int subsect_number;
459 short unsigned int module_number;
460 unsigned int offset;
461 unsigned int size;
465 * These are the values of interest that the subsect_number field takes.
467 #define sstAlignSym 0x125
468 #define sstSrcModule 0x127
470 struct codeview_linetab_hdr
472 unsigned int nline;
473 unsigned int segno;
474 unsigned int start;
475 unsigned int end;
476 char * sourcefile;
477 unsigned short * linetab;
478 unsigned int * offtab;
481 struct codeview_pdb_hdr
483 char ident[44];
484 unsigned int blocksize; /* Extent size */
485 unsigned short loc_freelist; /* freelist. */
486 unsigned short alloc_filesize; /* # extents allocated. */
487 unsigned int toc_len;
488 unsigned int unknown;
489 unsigned short toc_ext[1]; /* array of extent #'s for toc. */
493 * This is our own structure that we use to keep track of the contents
494 * of a PDB file.
496 struct file_list
498 int record_len;
499 int nextents;
500 short int * extent_list;
501 unsigned int linetab_offset;
502 unsigned int linetab_len;
506 * These are the structures that represent how the file table is set up
507 * within the PDB file.
509 struct filetab_hdr
511 unsigned short tab1_file;
512 unsigned short tab2_file;
513 unsigned short gsym_file;
514 unsigned short padding;
515 unsigned int ftab_len;
516 unsigned int fofftab_len;
517 unsigned int hash_len;
518 unsigned int strtab_len;
521 struct file_ent
523 unsigned int reserved1;
524 unsigned short datasect_segment;
525 unsigned short reserved2;
526 unsigned int datasect_offset;
527 unsigned int datasect_size;
528 unsigned int datasect_flags;
529 unsigned short reserved3;
530 unsigned short index;
531 unsigned short num6a;
532 unsigned short file_number;
533 unsigned int linetab_offset;
534 unsigned int linetab_len;
535 unsigned int num9;
536 unsigned int num10;
537 unsigned int num11;
538 unsigned char filename[1];
542 ********************************************************************
544 struct deferred_debug_info
546 struct deferred_debug_info * next;
547 char * load_addr;
548 char * module_name;
549 char * dbg_info;
550 int dbg_size;
551 HMODULE module;
552 PIMAGE_DEBUG_DIRECTORY dbgdir;
553 PIMAGE_SECTION_HEADER sectp;
554 int nsect;
555 short int dbg_index;
556 char status;
559 #define DF_STATUS_NEW 0
560 #define DF_STATUS_LOADED 1
561 #define DF_STATUS_ERROR 2
563 struct deferred_debug_info * dbglist = NULL;
566 * A simple macro that tells us whether a given COFF symbol is a
567 * function or not.
569 #define N_TMASK 0x0030
570 #define IMAGE_SYM_DTYPE_FUNCTION 2
571 #define N_BTSHFT 4
572 #define ISFCN(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_FUNCTION << N_BTSHFT))
576 * This is what we are looking for in the COFF symbols.
578 #define IMAGE_SYM_CLASS_EXTERNAL 0x2
579 #define IMAGE_SYM_CLASS_STATIC 0x3
580 #define IMAGE_SYM_CLASS_FILE 0x67
582 static
583 struct datatype * DEBUG_GetCVType(int typeno)
585 struct datatype * dt = NULL;
588 * Convert Codeview type numbers into something we can grok internally.
589 * Numbers < 0x1000 are all fixed builtin types. Numbers from 0x1000 and
590 * up are all user defined (structs, etc).
592 if( typeno < 0x1000 )
594 if( typeno < MAX_BUILTIN_TYPES )
596 dt = cv_basic_types[typeno];
599 else
601 if( typeno - 0x1000 < num_cv_defined_types )
603 dt = cv_defined_types[typeno - 0x1000];
607 return dt;
610 static int
611 DEBUG_ParseTypeTable(char * table, int len)
613 int arr_max;
614 int curr_type;
615 enum debug_type fieldtype;
616 int elem_size;
617 union any_size ptr;
618 union any_size ptr2;
619 struct datatype * subtype;
620 char symname[256];
621 union codeview_type * type;
622 union codeview_type * type2;
623 struct datatype * typeptr;
625 curr_type = 0x1000;
627 ptr.c = (table + 16);
628 while( ptr.c - table < len )
630 type = (union codeview_type *) ptr.c;
632 if( curr_type - 0x1000 >= num_cv_defined_types )
634 num_cv_defined_types += 0x100;
635 cv_defined_types = (struct datatype **) DBG_realloc(cv_defined_types,
636 num_cv_defined_types * sizeof(struct datatype *));
637 memset(cv_defined_types + num_cv_defined_types - 0x100,
639 0x100 * sizeof(struct datatype *));
640 if( cv_defined_types == NULL )
642 return FALSE;
646 switch(type->generic.id)
648 case LF_POINTER:
649 cv_defined_types[curr_type - 0x1000] =
650 DEBUG_FindOrMakePointerType(DEBUG_GetCVType(type->pointer.datatype));
651 break;
652 case LF_ARRAY:
653 if( type->array.arrlen >= 0x8000 )
656 * This is a numeric leaf, I am too lazy to handle this right
657 * now.
659 fprintf(stderr, "Ignoring large numberic leaf.\n");
660 break;
662 if( type->array.namelen != 0 )
664 memset(symname, 0, sizeof(symname));
665 memcpy(symname, type->array.name, type->array.namelen);
666 typeptr = DEBUG_NewDataType(DT_ARRAY, symname);
668 else
670 typeptr = DEBUG_NewDataType(DT_ARRAY, NULL);
672 cv_defined_types[curr_type - 0x1000] = typeptr;
674 subtype = DEBUG_GetCVType(type->array.elemtype);
675 if( (subtype == NULL)
676 || (elem_size = DEBUG_GetObjectSize(subtype)) == 0 )
678 arr_max = 0;
680 else
682 arr_max = type->array.arrlen / DEBUG_GetObjectSize(subtype);
685 DEBUG_SetArrayParams(typeptr, 0, arr_max, subtype);
686 break;
687 case LF_FIELDLIST:
689 * This is where the basic list of fields is defined for
690 * structures and classes.
692 * First, we need to look ahead and see whether we are building
693 * a fieldlist for an enum or a struct.
695 ptr2.i = ptr.i + 1;
696 type2 = (union codeview_type *) ptr2.c;
697 if( type2->member.id == LF_MEMBER )
699 typeptr = DEBUG_NewDataType(DT_STRUCT, NULL);
700 fieldtype = DT_STRUCT;
702 else if( type2->member.id == LF_ENUMERATE )
704 typeptr = DEBUG_NewDataType(DT_ENUM, NULL);
705 fieldtype = DT_ENUM;
707 else
709 break;
712 cv_defined_types[curr_type - 0x1000] = typeptr;
713 while( ptr2.c < (ptr.c + ((type->generic.len + 3) & ~3)) )
715 type2 = (union codeview_type *) ptr2.c;
716 if( type2->member.id == LF_MEMBER && fieldtype == DT_STRUCT )
718 memset(symname, 0, sizeof(symname));
719 memcpy(symname, type2->member.name, type2->member.namelen);
721 subtype = DEBUG_GetCVType(type2->member.type);
722 elem_size = 0;
723 if( subtype != NULL )
725 elem_size = DEBUG_GetObjectSize(subtype);
728 if( type2->member.offset >= 0x8000 )
731 * This is a numeric leaf, I am too lazy to handle this right
732 * now.
734 fprintf(stderr, "Ignoring large numberic leaf.\n");
736 else
738 DEBUG_AddStructElement(typeptr, symname, subtype,
739 type2->member.offset << 3,
740 elem_size << 3);
743 else if( type2->member.id == LF_ENUMERATE && fieldtype == DT_ENUM )
745 memset(symname, 0, sizeof(symname));
746 memcpy(symname, type2->enumerate.name, type2->enumerate.namelen);
748 if( type2->enumerate.value >= 0x8000 )
751 * This is a numeric leaf, I am too lazy to handle this right
752 * now.
754 fprintf(stderr, "Ignoring large numberic leaf.\n");
756 else
758 DEBUG_AddStructElement(typeptr, symname, NULL,
759 type2->enumerate.value, 0);
762 else
765 * Something else I have never seen before. Either wrong type of
766 * object in the fieldlist, or some other problem which I wouldn't
767 * really know how to handle until it came up.
769 fprintf(stderr, "Unexpected entry in fieldlist\n");
770 break;
774 ptr2.c += ((type2->member.namelen + 9 + 3) & ~3);
776 break;
777 case LF_STRUCTURE:
778 case LF_CLASS:
779 if( type->structure.structlen >= 0x8000 )
782 * This is a numeric leaf, I am too lazy to handle this right
783 * now.
785 fprintf(stderr, "Ignoring large numberic leaf.\n");
786 break;
788 memset(symname, 0, sizeof(symname));
789 memcpy(symname, type->structure.name, type->structure.namelen);
790 if( strcmp(symname, "__unnamed") == 0 )
792 typeptr = DEBUG_NewDataType(DT_STRUCT, NULL);
794 else
796 typeptr = DEBUG_NewDataType(DT_STRUCT, symname);
798 cv_defined_types[curr_type - 0x1000] = typeptr;
801 * Now copy the relevant bits from the fieldlist that we specified.
803 subtype = DEBUG_GetCVType(type->structure.fieldlist);
805 if( subtype != NULL )
807 DEBUG_SetStructSize(typeptr, type->structure.structlen);
808 DEBUG_CopyFieldlist(typeptr, subtype);
810 break;
811 case LF_UNION:
812 if( type->t_union.un_len >= 0x8000 )
815 * This is a numeric leaf, I am too lazy to handle this right
816 * now.
818 fprintf(stderr, "Ignoring large numberic leaf.\n");
819 break;
821 memset(symname, 0, sizeof(symname));
822 memcpy(symname, type->t_union.name, type->t_union.namelen);
824 if( strcmp(symname, "__unnamed") == 0 )
826 typeptr = DEBUG_NewDataType(DT_STRUCT, NULL);
828 else
830 typeptr = DEBUG_NewDataType(DT_STRUCT, symname);
833 cv_defined_types[curr_type - 0x1000] = typeptr;
836 * Now copy the relevant bits from the fieldlist that we specified.
838 subtype = DEBUG_GetCVType(type->t_union.field);
840 if( subtype != NULL )
842 DEBUG_SetStructSize(typeptr, type->t_union.un_len);
843 DEBUG_CopyFieldlist(typeptr, subtype);
845 break;
846 case LF_BITFIELD:
847 typeptr = DEBUG_NewDataType(DT_BITFIELD, NULL);
848 cv_defined_types[curr_type - 0x1000] = typeptr;
849 DEBUG_SetBitfieldParams(typeptr, type->bitfield.bitoff,
850 type->bitfield.nbits,
851 DEBUG_GetCVType(type->bitfield.type));
852 break;
853 case LF_ENUMERATION:
854 memset(symname, 0, sizeof(symname));
855 memcpy(symname, type->enumeration.name, type->enumeration.namelen);
856 typeptr = DEBUG_NewDataType(DT_ENUM, symname);
857 cv_defined_types[curr_type - 0x1000] = typeptr;
860 * Now copy the relevant bits from the fieldlist that we specified.
862 subtype = DEBUG_GetCVType(type->enumeration.field);
864 if( subtype != NULL )
866 DEBUG_CopyFieldlist(typeptr, subtype);
868 break;
869 case LF_DIMARRAY:
870 default:
871 break;
873 curr_type++;
874 ptr.c += (type->generic.len + 3) & ~3;
877 return TRUE;
880 void
881 DEBUG_InitCVDataTypes()
884 * These are the common builtin types that are used by VC++.
886 cv_basic_types[T_NOTYPE] = NULL;
887 cv_basic_types[T_ABS] = NULL;
888 cv_basic_types[T_VOID] = DEBUG_NewDataType(DT_BASIC, "void");
889 cv_basic_types[T_CHAR] = DEBUG_NewDataType(DT_BASIC, "char");
890 cv_basic_types[T_SHORT] = DEBUG_NewDataType(DT_BASIC, "short int");
891 cv_basic_types[T_LONG] = DEBUG_NewDataType(DT_BASIC, "long int");
892 cv_basic_types[T_QUAD] = DEBUG_NewDataType(DT_BASIC, "long long int");
893 cv_basic_types[T_UCHAR] = DEBUG_NewDataType(DT_BASIC, "unsigned char");
894 cv_basic_types[T_USHORT] = DEBUG_NewDataType(DT_BASIC, "short unsigned int");
895 cv_basic_types[T_ULONG] = DEBUG_NewDataType(DT_BASIC, "long unsigned int");
896 cv_basic_types[T_UQUAD] = DEBUG_NewDataType(DT_BASIC, "long long unsigned int");
897 cv_basic_types[T_REAL32] = DEBUG_NewDataType(DT_BASIC, "float");
898 cv_basic_types[T_REAL64] = DEBUG_NewDataType(DT_BASIC, "double");
899 cv_basic_types[T_RCHAR] = DEBUG_NewDataType(DT_BASIC, "char");
900 cv_basic_types[T_WCHAR] = DEBUG_NewDataType(DT_BASIC, "short");
901 cv_basic_types[T_INT4] = DEBUG_NewDataType(DT_BASIC, "int");
902 cv_basic_types[T_UINT4] = DEBUG_NewDataType(DT_BASIC, "unsigned int");
904 cv_basic_types[T_32PVOID] = DEBUG_FindOrMakePointerType(cv_basic_types[T_VOID]);
905 cv_basic_types[T_32PCHAR] = DEBUG_FindOrMakePointerType(cv_basic_types[T_CHAR]);
906 cv_basic_types[T_32PSHORT] = DEBUG_FindOrMakePointerType(cv_basic_types[T_SHORT]);
907 cv_basic_types[T_32PLONG] = DEBUG_FindOrMakePointerType(cv_basic_types[T_LONG]);
908 cv_basic_types[T_32PQUAD] = DEBUG_FindOrMakePointerType(cv_basic_types[T_QUAD]);
909 cv_basic_types[T_32PUCHAR] = DEBUG_FindOrMakePointerType(cv_basic_types[T_UCHAR]);
910 cv_basic_types[T_32PUSHORT] = DEBUG_FindOrMakePointerType(cv_basic_types[T_USHORT]);
911 cv_basic_types[T_32PULONG] = DEBUG_FindOrMakePointerType(cv_basic_types[T_ULONG]);
912 cv_basic_types[T_32PUQUAD] = DEBUG_FindOrMakePointerType(cv_basic_types[T_UQUAD]);
913 cv_basic_types[T_32PREAL32] = DEBUG_FindOrMakePointerType(cv_basic_types[T_REAL32]);
914 cv_basic_types[T_32PREAL64] = DEBUG_FindOrMakePointerType(cv_basic_types[T_REAL64]);
915 cv_basic_types[T_32PRCHAR] = DEBUG_FindOrMakePointerType(cv_basic_types[T_RCHAR]);
916 cv_basic_types[T_32PWCHAR] = DEBUG_FindOrMakePointerType(cv_basic_types[T_WCHAR]);
917 cv_basic_types[T_32PINT4] = DEBUG_FindOrMakePointerType(cv_basic_types[T_INT4]);
918 cv_basic_types[T_32PUINT4] = DEBUG_FindOrMakePointerType(cv_basic_types[T_UINT4]);
922 * In this function, we keep track of deferred debugging information
923 * that we may need later if we were to need to use the internal debugger.
924 * We don't fully process it here for performance reasons.
927 DEBUG_RegisterDebugInfo( HMODULE hModule, const char *module_name)
929 int has_codeview = FALSE;
930 int rtn = FALSE;
931 int orig_size;
932 PIMAGE_DEBUG_DIRECTORY dbgptr;
933 u_long v_addr, size;
934 PIMAGE_NT_HEADERS nth = PE_HEADER(hModule);
936 size = nth->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].Size;
937 if (size) {
938 v_addr = nth->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress;
939 dbgptr = (PIMAGE_DEBUG_DIRECTORY) (hModule + v_addr);
940 orig_size = size;
941 for(; size >= sizeof(*dbgptr); size -= sizeof(*dbgptr), dbgptr++ )
943 switch(dbgptr->Type)
945 case IMAGE_DEBUG_TYPE_CODEVIEW:
946 case IMAGE_DEBUG_TYPE_MISC:
947 has_codeview = TRUE;
948 break;
952 size = orig_size;
953 dbgptr = (PIMAGE_DEBUG_DIRECTORY) (hModule + v_addr);
954 for(; size >= sizeof(*dbgptr); size -= sizeof(*dbgptr), dbgptr++ )
956 switch(dbgptr->Type)
958 case IMAGE_DEBUG_TYPE_COFF:
960 * If we have both codeview and COFF debug info, ignore the
961 * coff debug info as it would just confuse us, and it is
962 * less complete.
964 * FIXME - this is broken - if we cannot find the PDB file, then
965 * we end up with no debugging info at all. In this case, we
966 * should use the COFF info as a backup.
968 if( has_codeview )
970 break;
972 case IMAGE_DEBUG_TYPE_CODEVIEW:
973 case IMAGE_DEBUG_TYPE_MISC:
975 * This is usually an indirection to a .DBG file.
976 * This is similar to (but a slightly older format) from the
977 * PDB file.
979 * First check to see if the image was 'stripped'. If so, it
980 * means that this entry points to a .DBG file. Otherwise,
981 * it just points to itself, and we can ignore this.
989 if( (dbgptr->Type != IMAGE_DEBUG_TYPE_MISC) ||
990 (PE_HEADER(hModule)->FileHeader.Characteristics & IMAGE_FILE_DEBUG_STRIPPED) != 0 )
992 char fn[PATH_MAX];
993 int fd = -1;
994 DOS_FULL_NAME full_name;
995 struct deferred_debug_info* deefer = (struct deferred_debug_info *) DBG_alloc(sizeof(*deefer));
997 deefer->module = hModule;
998 deefer->load_addr = (char *)hModule;
1001 * Read the important bits. What we do after this depends
1002 * upon the type, but this is always enough so we are able
1003 * to proceed if we know what we need to do next.
1005 /* basically, the PE loader maps all sections (data, resources...), but doesn't map
1006 * the DataDirectory array's content. One its entry contains the *beloved*
1007 * debug information. (Note the DataDirectory is mapped, not its content)
1010 if (GetModuleFileNameA(hModule, fn, sizeof(fn)) > 0 &&
1011 DOSFS_GetFullName(fn, TRUE, &full_name) &&
1012 (fd = open(full_name.long_name, O_RDONLY)) > 0)
1014 deefer->dbg_info = mmap(NULL, dbgptr->SizeOfData,
1015 PROT_READ, MAP_PRIVATE, fd, dbgptr->PointerToRawData);
1016 close(fd);
1017 if( deefer->dbg_info == (char *) 0xffffffff )
1019 DBG_free(deefer);
1020 break;
1023 else
1025 DBG_free(deefer);
1026 fprintf(stderr, " (not mapped: fn=%s, lfn=%s, fd=%d)", fn, full_name.long_name, fd);
1027 break;
1029 deefer->dbg_size = dbgptr->SizeOfData;
1030 deefer->dbgdir = dbgptr;
1031 deefer->next = dbglist;
1032 deefer->status = DF_STATUS_NEW;
1033 deefer->dbg_index = DEBUG_next_index;
1034 deefer->module_name = DBG_strdup(module_name);
1036 deefer->sectp = PE_SECTIONS(hModule);
1037 deefer->nsect = PE_HEADER(hModule)->FileHeader.NumberOfSections;
1039 dbglist = deefer;
1041 break;
1042 #if 0
1043 default:
1044 #endif
1047 DEBUG_next_index++;
1049 /* look for .stabs/.stabstr sections */
1051 PIMAGE_SECTION_HEADER pe_seg = PE_SECTIONS(hModule);
1052 int i,stabsize=0,stabstrsize=0;
1053 unsigned int stabs=0,stabstr=0;
1055 for (i=0;i<nth->FileHeader.NumberOfSections;i++) {
1056 if (!strcasecmp(pe_seg[i].Name,".stab")) {
1057 stabs = pe_seg[i].VirtualAddress;
1058 stabsize = pe_seg[i].SizeOfRawData;
1060 if (!strncasecmp(pe_seg[i].Name,".stabstr",8)) {
1061 stabstr = pe_seg[i].VirtualAddress;
1062 stabstrsize = pe_seg[i].SizeOfRawData;
1065 if (stabstrsize && stabsize) {
1066 #ifdef _WE_SUPPORT_THE_STAB_TYPES_USED_BY_MINGW_TOO
1067 /* Won't work currently, since MINGW32 uses some special typedefs
1068 * which we do not handle yet. Support for them is a bit difficult.
1070 DEBUG_ParseStabs(hModule,0,stabs,stabsize,stabstr,stabstrsize);
1071 #endif
1072 fprintf(stderr,"(stabs not loaded)");
1075 return (rtn);
1079 * ELF modules are also entered into the list - this is so that we
1080 * can make 'info shared' types of displays possible.
1083 DEBUG_RegisterELFDebugInfo(int load_addr, u_long size, char * name)
1085 struct deferred_debug_info * deefer;
1087 deefer = (struct deferred_debug_info *) DBG_alloc(sizeof(*deefer));
1088 deefer->module = 0;
1091 * Read the important bits. What we do after this depends
1092 * upon the type, but this is always enough so we are able
1093 * to proceed if we know what we need to do next.
1095 deefer->dbg_size = size;
1096 deefer->dbg_info = (char *) NULL;
1098 deefer->load_addr = (char *) load_addr;
1099 deefer->dbgdir = NULL;
1100 deefer->next = dbglist;
1101 deefer->status = DF_STATUS_LOADED;
1102 deefer->dbg_index = DEBUG_next_index;
1103 deefer->module_name = DBG_strdup(name);
1104 dbglist = deefer;
1106 DEBUG_next_index++;
1108 return (TRUE);
1114 * Process COFF debugging information embedded in a Win32 application.
1117 static
1119 DEBUG_ProcessCoff(struct deferred_debug_info * deefer)
1121 struct CoffAuxSection * aux;
1122 struct CoffDebug * coff;
1123 struct CoffFiles * coff_files = NULL;
1124 struct CoffLinenum * coff_linetab;
1125 char * coff_strtab;
1126 struct CoffSymbol * coff_sym;
1127 struct CoffSymbol * coff_symbol;
1128 struct CoffFiles * curr_file = NULL;
1129 int i;
1130 int j;
1131 int k;
1132 struct CoffLinenum * linepnt;
1133 int linetab_indx;
1134 char namebuff[9];
1135 char * nampnt;
1136 int naux;
1137 DBG_ADDR new_addr;
1138 int nfiles = 0;
1139 int nfiles_alloc = 0;
1140 struct CoffFiles orig_file;
1141 int rtn = FALSE;
1142 char * this_file = NULL;
1144 coff = (struct CoffDebug *) deefer->dbg_info;
1146 coff_symbol = (struct CoffSymbol *) ((unsigned int) coff + coff->SymbolOffset);
1147 coff_linetab = (struct CoffLinenum *) ((unsigned int) coff + coff->LinenumberOffset);
1148 coff_strtab = (char *) ((unsigned int) coff_symbol + 18*coff->N_Sym);
1150 linetab_indx = 0;
1152 for(i=0; i < coff->N_Sym; i++ )
1155 * We do this because some compilers (i.e. gcc) incorrectly
1156 * pad the structure up to a 4 byte boundary. The structure
1157 * is really only 18 bytes long, so we have to manually make sure
1158 * we get it right.
1160 * FIXME - there must be a way to have autoconf figure out the
1161 * correct compiler option for this. If it is always gcc, that
1162 * makes life simpler, but I don't want to force this.
1164 coff_sym = (struct CoffSymbol *) ((unsigned int) coff_symbol + 18*i);
1165 naux = coff_sym->NumberOfAuxSymbols;
1167 if( coff_sym->StorageClass == IMAGE_SYM_CLASS_FILE )
1169 if( nfiles + 1 >= nfiles_alloc )
1171 nfiles_alloc += 10;
1172 coff_files = (struct CoffFiles *) DBG_realloc(coff_files,
1173 nfiles_alloc * sizeof(struct CoffFiles));
1175 curr_file = coff_files + nfiles;
1176 nfiles++;
1177 curr_file->startaddr = 0xffffffff;
1178 curr_file->endaddr = 0;
1179 curr_file->filename = ((char *) coff_sym) + 18;
1180 curr_file->linetab_offset = -1;
1181 curr_file->linecnt = 0;
1182 curr_file->entries = NULL;
1183 curr_file->neps = curr_file->neps_alloc = 0;
1184 #if 0
1185 fprintf(stderr,"New file %s\n", curr_file->filename);
1186 #endif
1187 i += naux;
1188 continue;
1192 * This guy marks the size and location of the text section
1193 * for the current file. We need to keep track of this so
1194 * we can figure out what file the different global functions
1195 * go with.
1197 if( (coff_sym->StorageClass == IMAGE_SYM_CLASS_STATIC)
1198 && (naux != 0)
1199 && (coff_sym->Type == 0)
1200 && (coff_sym->SectionNumber == 1) )
1202 aux = (struct CoffAuxSection *) ((unsigned int) coff_sym + 18);
1204 if( curr_file->linetab_offset != -1 )
1206 #if 0
1207 fprintf(stderr, "Duplicating sect from %s: %x %x %x %d %d\n",
1208 curr_file->filename,
1209 aux->Length,
1210 aux->NumberOfRelocations,
1211 aux->NumberOfLinenumbers,
1212 aux->Number,
1213 aux->Selection);
1214 fprintf(stderr, "More sect %d %x %d %d %d\n",
1215 coff_sym->SectionNumber,
1216 coff_sym->Value,
1217 coff_sym->Type,
1218 coff_sym->StorageClass,
1219 coff_sym->NumberOfAuxSymbols);
1220 #endif
1223 * Save this so we can copy bits from it.
1225 orig_file = *curr_file;
1228 * Duplicate the file entry. We have no way to describe
1229 * multiple text sections in our current way of handling things.
1231 if( nfiles + 1 >= nfiles_alloc )
1233 nfiles_alloc += 10;
1234 coff_files = (struct CoffFiles *) DBG_realloc(coff_files,
1235 nfiles_alloc * sizeof(struct CoffFiles));
1237 curr_file = coff_files + nfiles;
1238 nfiles++;
1239 curr_file->startaddr = 0xffffffff;
1240 curr_file->endaddr = 0;
1241 curr_file->filename = orig_file.filename;
1242 curr_file->linetab_offset = -1;
1243 curr_file->linecnt = 0;
1244 curr_file->entries = NULL;
1245 curr_file->neps = curr_file->neps_alloc = 0;
1247 #if 0
1248 else
1250 fprintf(stderr, "New text sect from %s: %x %x %x %d %d\n",
1251 curr_file->filename,
1252 aux->Length,
1253 aux->NumberOfRelocations,
1254 aux->NumberOfLinenumbers,
1255 aux->Number,
1256 aux->Selection);
1258 #endif
1260 if( curr_file->startaddr > coff_sym->Value )
1262 curr_file->startaddr = coff_sym->Value;
1265 if( curr_file->startaddr > coff_sym->Value )
1267 curr_file->startaddr = coff_sym->Value;
1270 if( curr_file->endaddr < coff_sym->Value + aux->Length )
1272 curr_file->endaddr = coff_sym->Value + aux->Length;
1275 curr_file->linetab_offset = linetab_indx;
1276 curr_file->linecnt = aux->NumberOfLinenumbers;
1277 linetab_indx += aux->NumberOfLinenumbers;
1278 i += naux;
1279 continue;
1282 if( (coff_sym->StorageClass == IMAGE_SYM_CLASS_STATIC)
1283 && (naux == 0)
1284 && (coff_sym->SectionNumber == 1) )
1287 * This is a normal static function when naux == 0.
1288 * Just register it. The current file is the correct
1289 * one in this instance.
1291 if( coff_sym->N.Name.NotLong )
1293 memcpy(namebuff, coff_sym->N.ShortName, 8);
1294 namebuff[8] = '\0';
1295 nampnt = &namebuff[0];
1297 else
1299 nampnt = coff_strtab + coff_sym->N.Name.StrTaboff;
1302 if( nampnt[0] == '_' )
1304 nampnt++;
1307 new_addr.seg = 0;
1308 new_addr.off = (int) (deefer->load_addr + coff_sym->Value);
1310 if( curr_file->neps + 1 >= curr_file->neps_alloc )
1312 curr_file->neps_alloc += 10;
1313 curr_file->entries = (struct name_hash **)
1314 DBG_realloc(curr_file->entries,
1315 curr_file->neps_alloc * sizeof(struct name_hash *));
1317 #if 0
1318 fprintf(stderr,"\tAdding static symbol %s\n", nampnt);
1319 #endif
1320 curr_file->entries[curr_file->neps++] =
1321 DEBUG_AddSymbol( nampnt, &new_addr, this_file, SYM_WIN32 );
1322 i += naux;
1323 continue;
1326 if( (coff_sym->StorageClass == IMAGE_SYM_CLASS_EXTERNAL)
1327 && ISFCN(coff_sym->Type)
1328 && (coff_sym->SectionNumber > 0) )
1330 if( coff_sym->N.Name.NotLong )
1332 memcpy(namebuff, coff_sym->N.ShortName, 8);
1333 namebuff[8] = '\0';
1334 nampnt = &namebuff[0];
1336 else
1338 nampnt = coff_strtab + coff_sym->N.Name.StrTaboff;
1342 if( nampnt[0] == '_' )
1344 nampnt++;
1347 new_addr.seg = 0;
1348 new_addr.off = (int) (deefer->load_addr + coff_sym->Value);
1350 #if 0
1351 fprintf(stderr, "%d: %x %s\n", i, new_addr.off, nampnt);
1353 fprintf(stderr,"\tAdding global symbol %s\n", nampnt);
1354 #endif
1357 * Now we need to figure out which file this guy belongs to.
1359 this_file = NULL;
1360 for(j=0; j < nfiles; j++)
1362 if( coff_files[j].startaddr <= coff_sym->Value
1363 && coff_files[j].endaddr > coff_sym->Value )
1365 this_file = coff_files[j].filename;
1366 break;
1369 if( coff_files[j].neps + 1 >= coff_files[j].neps_alloc )
1371 coff_files[j].neps_alloc += 10;
1372 coff_files[j].entries = (struct name_hash **)
1373 DBG_realloc(coff_files[j].entries,
1374 coff_files[j].neps_alloc * sizeof(struct name_hash *));
1376 coff_files[j].entries[coff_files[j].neps++] =
1377 DEBUG_AddSymbol( nampnt, &new_addr, this_file, SYM_WIN32 );
1378 i += naux;
1379 continue;
1382 if( (coff_sym->StorageClass == IMAGE_SYM_CLASS_EXTERNAL)
1383 && (coff_sym->SectionNumber > 0) )
1386 * Similar to above, but for the case of data symbols.
1387 * These aren't treated as entrypoints.
1389 if( coff_sym->N.Name.NotLong )
1391 memcpy(namebuff, coff_sym->N.ShortName, 8);
1392 namebuff[8] = '\0';
1393 nampnt = &namebuff[0];
1395 else
1397 nampnt = coff_strtab + coff_sym->N.Name.StrTaboff;
1401 if( nampnt[0] == '_' )
1403 nampnt++;
1406 new_addr.seg = 0;
1407 new_addr.off = (int) (deefer->load_addr + coff_sym->Value);
1409 #if 0
1410 fprintf(stderr, "%d: %x %s\n", i, new_addr.off, nampnt);
1412 fprintf(stderr,"\tAdding global data symbol %s\n", nampnt);
1413 #endif
1416 * Now we need to figure out which file this guy belongs to.
1418 DEBUG_AddSymbol( nampnt, &new_addr, NULL, SYM_WIN32 );
1419 i += naux;
1420 continue;
1423 if( (coff_sym->StorageClass == IMAGE_SYM_CLASS_STATIC)
1424 && (naux == 0) )
1427 * Ignore these. They don't have anything to do with
1428 * reality.
1430 i += naux;
1431 continue;
1434 #if 0
1435 fprintf(stderr,"Skipping unknown entry %d %d %d\n", coff_sym->StorageClass,
1436 coff_sym->SectionNumber, naux);
1437 #endif
1440 * For now, skip past the aux entries.
1442 i += naux;
1447 * OK, we now should have a list of files, and we should have a list
1448 * of entrypoints. We need to sort the entrypoints so that we are
1449 * able to tie the line numbers with the given functions within the
1450 * file.
1452 if( coff_files != NULL )
1454 for(j=0; j < nfiles; j++)
1456 if( coff_files[j].entries != NULL )
1458 qsort(coff_files[j].entries, coff_files[j].neps,
1459 sizeof(struct name_hash *), DEBUG_cmp_sym);
1464 * Now pick apart the line number tables, and attach the entries
1465 * to the given functions.
1467 for(j=0; j < nfiles; j++)
1469 i = 0;
1470 if( coff_files[j].neps != 0 )
1471 for(k=0; k < coff_files[j].linecnt; k++)
1474 * Another monstrosity caused by the fact that we are using
1475 * a 6 byte structure, and gcc wants to pad structures to 4 byte
1476 * boundaries. Otherwise we could just index into an array.
1478 linepnt = (struct CoffLinenum *)
1479 ((unsigned int) coff_linetab +
1480 6*(coff_files[j].linetab_offset + k));
1482 * If we have spilled onto the next entrypoint, then
1483 * bump the counter..
1485 while(TRUE)
1487 if (i+1 >= coff_files[j].neps) break;
1488 DEBUG_GetSymbolAddr(coff_files[j].entries[i+1], &new_addr);
1489 if( (((unsigned int)deefer->load_addr +
1490 linepnt->VirtualAddr) >= new_addr.off) )
1492 i++;
1493 } else break;
1497 * Add the line number. This is always relative to the
1498 * start of the function, so we need to subtract that offset
1499 * first.
1501 DEBUG_GetSymbolAddr(coff_files[j].entries[i], &new_addr);
1502 DEBUG_AddLineNumber(coff_files[j].entries[i],
1503 linepnt->Linenum,
1504 (unsigned int) deefer->load_addr
1505 + linepnt->VirtualAddr
1506 - new_addr.off);
1511 rtn = TRUE;
1513 if( coff_files != NULL )
1515 for(j=0; j < nfiles; j++)
1517 if( coff_files[j].entries != NULL )
1519 DBG_free(coff_files[j].entries);
1522 DBG_free(coff_files);
1525 return (rtn);
1530 * Process a codeview line number table. Digestify the thing so that
1531 * we can easily reference the thing when we process the rest of
1532 * the information.
1534 static struct codeview_linetab_hdr *
1535 DEBUG_SnarfLinetab(char * linetab,
1536 int size)
1538 int file_segcount;
1539 char filename[PATH_MAX];
1540 unsigned int * filetab;
1541 char * fn;
1542 int i;
1543 int k;
1544 struct codeview_linetab_hdr * lt_hdr;
1545 unsigned int * lt_ptr;
1546 int nfile;
1547 int nseg;
1548 union any_size pnt;
1549 union any_size pnt2;
1550 struct startend * start;
1551 int this_seg;
1554 * Now get the important bits.
1556 pnt.c = linetab;
1557 nfile = *pnt.s++;
1558 nseg = *pnt.s++;
1560 filetab = (unsigned int *) pnt.c;
1563 * Now count up the number of segments in the file.
1565 nseg = 0;
1566 for(i=0; i<nfile; i++)
1568 pnt2.c = linetab + filetab[i];
1569 nseg += *pnt2.s;
1573 * Next allocate the header we will be returning.
1574 * There is one header for each segment, so that we can reach in
1575 * and pull bits as required.
1577 lt_hdr = (struct codeview_linetab_hdr *)
1578 DBG_alloc((nseg + 1) * sizeof(*lt_hdr));
1579 if( lt_hdr == NULL )
1581 goto leave;
1584 memset(lt_hdr, 0, sizeof(*lt_hdr) * (nseg+1));
1587 * Now fill the header we will be returning, one for each segment.
1588 * Note that this will basically just contain pointers into the existing
1589 * line table, and we do not actually copy any additional information
1590 * or allocate any additional memory.
1593 this_seg = 0;
1594 for(i=0; i<nfile; i++)
1597 * Get the pointer into the segment information.
1599 pnt2.c = linetab + filetab[i];
1600 file_segcount = *pnt2.s;
1602 pnt2.ui++;
1603 lt_ptr = (unsigned int *) pnt2.c;
1604 start = (struct startend *) (lt_ptr + file_segcount);
1607 * Now snarf the filename for all of the segments for this file.
1609 fn = (unsigned char *) (start + file_segcount);
1610 memset(filename, 0, sizeof(filename));
1611 memcpy(filename, fn + 1, *fn);
1612 fn = DBG_strdup(filename);
1614 for(k = 0; k < file_segcount; k++, this_seg++)
1616 pnt2.c = linetab + lt_ptr[k];
1617 lt_hdr[this_seg].start = start[k].start;
1618 lt_hdr[this_seg].end = start[k].end;
1619 lt_hdr[this_seg].sourcefile = fn;
1620 lt_hdr[this_seg].segno = *pnt2.s++;
1621 lt_hdr[this_seg].nline = *pnt2.s++;
1622 lt_hdr[this_seg].offtab = pnt2.ui;
1623 lt_hdr[this_seg].linetab = (unsigned short *)
1624 (pnt2.ui + lt_hdr[this_seg].nline);
1628 leave:
1630 return lt_hdr;
1634 static int
1635 DEBUG_SnarfCodeView( struct deferred_debug_info * deefer,
1636 char * cv_data,
1637 int size,
1638 struct codeview_linetab_hdr * linetab)
1640 struct name_hash * curr_func = NULL;
1641 struct wine_locals * curr_sym = NULL;
1642 int i;
1643 int j;
1644 int len;
1645 DBG_ADDR new_addr;
1646 int nsect;
1647 union any_size ptr;
1648 IMAGE_SECTION_HEADER * sectp;
1649 union codeview_symbol * sym;
1650 char symname[PATH_MAX];
1651 struct name_hash * thunk_sym = NULL;
1653 ptr.c = cv_data;
1654 nsect = deefer->nsect;
1655 sectp = deefer->sectp;
1658 * Skip over the first word. Don't really know what it means, but
1659 * it is useless.
1661 ptr.ui++;
1664 * Loop over the different types of records and whenever we
1665 * find something we are interested in, record it and move on.
1667 while( ptr.c - cv_data < size )
1669 sym = (union codeview_symbol *) ptr.c;
1671 if( sym->generic.len - sizeof(int) == (ptr.c - cv_data) )
1674 * This happens when we have indirect symbols that VC++ 4.2
1675 * sometimes uses when there isn't a line number table.
1676 * We ignore it - we will process and enter all of the
1677 * symbols in the global symbol table anyways, so there
1678 * isn't much point in keeping track of all of this crap.
1680 break;
1683 memset(symname, 0, sizeof(symname));
1684 switch(sym->generic.id)
1686 case S_GDATA:
1687 case S_LDATA:
1688 case S_PUB:
1690 * First, a couple of sanity checks.
1692 if( sym->data.namelen == 0 )
1694 break;
1697 if( sym->data.seg == 0 || sym->data.seg > nsect )
1699 break;
1703 * Global and local data symbols. We don't associate these
1704 * with any given source file.
1707 memcpy(symname, sym->data.name, sym->data.namelen);
1708 new_addr.seg = 0;
1709 new_addr.type = DEBUG_GetCVType(sym->data.symtype);
1710 new_addr.off = (unsigned int) deefer->load_addr +
1711 sectp[sym->data.seg - 1].VirtualAddress +
1712 sym->data.offset;
1713 DEBUG_AddSymbol( symname, &new_addr, NULL, SYM_WIN32 | SYM_DATA );
1714 break;
1715 case S_THUNK:
1717 * Sort of like a global function, but it just points
1718 * to a thunk, which is a stupid name for what amounts to
1719 * a PLT slot in the normal jargon that everyone else uses.
1721 memcpy(symname, sym->thunk.name, sym->thunk.namelen);
1722 new_addr.seg = 0;
1723 new_addr.type = NULL;
1724 new_addr.off = (unsigned int) deefer->load_addr +
1725 sectp[sym->thunk.segment - 1].VirtualAddress +
1726 sym->thunk.offset;
1727 thunk_sym = DEBUG_AddSymbol( symname, &new_addr, NULL,
1728 SYM_WIN32 | SYM_FUNC);
1729 DEBUG_SetSymbolSize(thunk_sym, sym->thunk.thunk_len);
1730 break;
1731 case S_GPROC:
1732 case S_LPROC:
1734 * Global and static functions.
1736 memcpy(symname, sym->proc.name, sym->proc.namelen);
1737 new_addr.seg = 0;
1738 new_addr.type = DEBUG_GetCVType(sym->proc.proctype);
1739 new_addr.off = (unsigned int) deefer->load_addr +
1740 sectp[sym->proc.segment - 1].VirtualAddress +
1741 sym->proc.offset;
1743 * See if we can find a segment that this goes with. If so,
1744 * it means that we also may have line number information
1745 * for this function.
1747 for(i=0; linetab[i].linetab != NULL; i++)
1749 if( ((unsigned int) deefer->load_addr
1750 + sectp[linetab[i].segno - 1].VirtualAddress
1751 + linetab[i].start <= new_addr.off)
1752 && ((unsigned int) deefer->load_addr
1753 + sectp[linetab[i].segno - 1].VirtualAddress
1754 + linetab[i].end > new_addr.off) )
1756 break;
1760 DEBUG_Normalize(curr_func);
1761 if( linetab[i].linetab == NULL )
1763 curr_func = DEBUG_AddSymbol( symname, &new_addr, NULL,
1764 SYM_WIN32 | SYM_FUNC);
1766 else
1769 * First, create the entry. Then dig through the linetab
1770 * and add whatever line numbers are appropriate for this
1771 * function.
1773 curr_func = DEBUG_AddSymbol( symname, &new_addr,
1774 linetab[i].sourcefile,
1775 SYM_WIN32 | SYM_FUNC);
1776 for(j=0; j < linetab[i].nline; j++)
1778 if( linetab[i].offtab[j] >= sym->proc.offset
1779 && linetab[i].offtab[j] < sym->proc.offset
1780 + sym->proc.proc_len )
1782 DEBUG_AddLineNumber(curr_func, linetab[i].linetab[j],
1783 linetab[i].offtab[j] - sym->proc.offset);
1790 * Add information about where we should set breakpoints
1791 * in this function.
1793 DEBUG_SetSymbolBPOff(curr_func, sym->proc.debug_start);
1794 DEBUG_SetSymbolSize(curr_func, sym->proc.proc_len);
1795 break;
1796 case S_BPREL:
1798 * Function parameters and stack variables.
1800 memcpy(symname, sym->stack.name, sym->stack.namelen);
1801 curr_sym = DEBUG_AddLocal(curr_func,
1803 sym->stack.offset,
1806 symname);
1807 DEBUG_SetLocalSymbolType(curr_sym, DEBUG_GetCVType(sym->stack.symtype));
1809 break;
1810 default:
1811 break;
1815 * Adjust pointer to point to next entry, rounding up to a word
1816 * boundary. MS preserving alignment? Stranger things have
1817 * happened.
1819 if( sym->generic.id == S_PROCREF
1820 || sym->generic.id == S_DATAREF
1821 || sym->generic.id == S_UNKNOWN )
1823 len = (sym->generic.len + 3) & ~3;
1824 len += ptr.c[16] + 1;
1825 ptr.c += (len + 3) & ~3;
1827 else
1829 ptr.c += (sym->generic.len + 3) & ~3;
1833 if( linetab != NULL )
1835 DBG_free(linetab);
1838 return TRUE;
1843 * Process PDB file which contains debug information.
1845 * These are really weird beasts. They are intended to be incrementally
1846 * updated by the incremental linker, and this means that you need to
1847 * be able to remove and add information. Thus the PDB file is sort of
1848 * like a block structured device, with a freelist and lists of extent numbers
1849 * that are used to get the relevant pieces. In all cases seen so far, the
1850 * blocksize is always 0x400 bytes. The header has a field which apparently
1851 * holds the blocksize, so if it ever changes we are safe.
1853 * In general, every time we need to extract something from the pdb file,
1854 * it is easier to copy it into another buffer so we have the information
1855 * in one contiguous block rather than attempt to try and keep track of when
1856 * we need to grab another extent from the pdb file.
1858 * The thing that is a real pain about some MS stuff is that they choose
1859 * data structures which are not representable in C. Thus we have to
1860 * hack around and diddle pointers.
1862 /* static */
1864 DEBUG_ProcessPDBFile(struct deferred_debug_info * deefer, char * full_filename)
1866 char * addr = (char *) 0xffffffff;
1867 unsigned int blocksize;
1868 unsigned int bufflen = 0;
1869 char * buffer = NULL;
1870 unsigned short * extent_table;
1871 int fd = -1;
1872 struct file_ent * fent;
1873 char filename[MAX_PATHNAME_LEN];
1874 struct file_list * filelist = NULL;
1875 unsigned int gsym_record = 0;
1876 char * gsymtab = NULL;
1877 struct filetab_hdr * hd;
1878 int i;
1879 int j;
1880 unsigned int last_extent;
1881 struct codeview_linetab_hdr * linetab;
1882 unsigned int nblocks;
1883 unsigned int npair;
1884 unsigned int offset;
1885 struct codeview_pdb_hdr * pdbhdr;
1886 unsigned int * pnt;
1887 struct stat statbuf;
1888 int status;
1889 unsigned short * table;
1890 char * toc;
1891 unsigned int toc_blocks;
1893 LocateDebugInfoFile(full_filename, filename);
1894 status = stat(filename, &statbuf);
1895 if( status == -1 )
1897 fprintf(stderr, "-Unable to open .PDB file %s\n", filename);
1898 goto leave;
1902 * Now open the file, so that we can mmap() it.
1904 fd = open(filename, O_RDONLY);
1905 if( fd == -1 )
1907 fprintf(stderr, "-Unable to open .DBG file %s\n", filename);
1908 goto leave;
1913 * Now mmap() the file.
1915 addr = mmap(0, statbuf.st_size, PROT_READ,
1916 MAP_PRIVATE, fd, 0);
1917 if( addr == (char *) 0xffffffff )
1919 fprintf(stderr, "-Unable to mmap .DBG file %s\n", filename);
1920 goto leave;
1924 * Now that we have the formalities over and done with, we need
1925 * to find the table of contents for the PDB file.
1927 pdbhdr = (struct codeview_pdb_hdr *) addr;
1928 blocksize = pdbhdr->blocksize;
1929 last_extent = (statbuf.st_size + blocksize - 1) / blocksize;
1932 * The TOC itself isn't always contiguous, so we need to extract a few
1933 * extents from the file to form the TOC.
1935 toc_blocks = (pdbhdr->toc_len + blocksize - 1) / blocksize;
1936 toc = (char *) DBG_alloc(toc_blocks * blocksize);
1937 table = pdbhdr->toc_ext;
1938 for(i=0; i < toc_blocks; i++)
1940 memcpy(toc + blocksize*i, addr + table[i]*blocksize, blocksize);
1944 * Next build our own table which will have the size and extent block
1945 * list for each record in the PDB file.
1947 * The TOC starts out with the number of files. Then it is followed by
1948 * (npair * 2*sizeof(int)) bytes of information, which are pairs of ints.
1949 * The first one is the size of the record (in bytes), and the second one
1950 * is something else which I haven't figured out yet.
1952 pnt = (unsigned int *) toc;
1953 npair = *pnt++;
1954 extent_table = (unsigned short *) ((unsigned int) toc +
1955 npair * 2 * sizeof(int) + sizeof(int));
1958 * Sanity check.
1960 if( sizeof(int) + 2*sizeof(int)*npair > pdbhdr->toc_len )
1962 goto leave;
1965 filelist = (struct file_list *) DBG_alloc(npair * sizeof(*filelist));
1966 if( filelist == NULL )
1968 goto leave;
1970 memset(filelist, 0, npair * sizeof(*filelist));
1972 nblocks = 0;
1973 for(i=0; i < npair; i++)
1975 filelist[i].record_len = pnt[i*2];
1976 filelist[i].nextents = (filelist[i].record_len + blocksize - 1)
1977 / blocksize;
1978 filelist[i].extent_list = extent_table + nblocks;
1979 nblocks += filelist[i].nextents;
1982 * These get filled in later when we parse one of the records.
1984 filelist[i].linetab_offset = 0;
1985 filelist[i].linetab_len = 0;
1989 * OK, now walk through the various records and pick out the bits we
1990 * really want to see. Some of the records are extra special, and
1991 * we need to handle these a little bit differently.
1993 for(i=0; i < npair; i++)
1995 if( filelist[i].record_len == 0xffffffff )
1997 continue;
2001 * Make sure our buffer is large enough to hold the record.
2003 if( bufflen < filelist[i].nextents * blocksize )
2005 bufflen = filelist[i].nextents * blocksize;
2006 buffer = (char *) DBG_realloc(buffer, bufflen);
2010 * Do this just for completeness. It makes debugging easier
2011 * if we have a clean indication of where the record ends.
2013 memset(buffer, 0, filelist[i].nextents * blocksize);
2016 * Next, build the record using the extent list.
2018 for(j=0; j < filelist[i].nextents; j++)
2020 memcpy(buffer + j * blocksize,
2021 addr + filelist[i].extent_list[j] * blocksize,
2022 blocksize);
2025 pnt = (unsigned int *) buffer;
2028 * OK, now figure out what to do with it.
2032 * Always ignore the first entry. It seems to contain a backup copy
2033 * of the TOC (the last time the file was modified??)
2035 if( i == 0 )
2037 continue;
2041 * The second entry as a id block. It contains a magic number
2042 * to identify the compiler, plus it also contains the timestamp
2043 * which must match the timestamp in the executable.
2045 if( i == 1 )
2048 if( ((*pnt != 19950623) && (*pnt != 19950814))
2049 || (filelist[i].record_len != 0x24)
2050 || (pnt[1] != ((struct CodeViewDebug *)(deefer->dbg_info))->cv_timestamp) )
2052 goto leave;
2057 * The third entry contains pointers to the global symbol table,
2058 * plus it also contains additional information about each record
2059 * in the PDB file.
2061 if( i == 3 )
2063 hd = (struct filetab_hdr *) buffer;
2065 gsym_record = hd->gsym_file;
2066 gsymtab = (char *) DBG_alloc(filelist[gsym_record].nextents
2067 * blocksize);
2068 memset(gsymtab, 0, filelist[gsym_record].nextents * blocksize);
2070 for(j=0; j < filelist[gsym_record].nextents; j++)
2072 memcpy(gsymtab + j * blocksize,
2073 addr + filelist[gsym_record].extent_list[j] * blocksize,
2074 blocksize);
2078 * This record also contains information about where in the
2079 * remaining records we will be able to find the start of the
2080 * line number table. We could locate that bit using heuristics,
2081 * but since we have the info handy, we might as well use it.
2083 offset = sizeof(*hd);
2084 while(1==1)
2086 fent = (struct file_ent *) (buffer + offset);
2087 if( offset > hd->ftab_len )
2089 break;
2092 if( fent->file_number == 0 || fent->file_number >= npair )
2094 break;
2097 filelist[fent->file_number].linetab_offset =
2098 fent->linetab_offset;
2099 filelist[fent->file_number].linetab_len =
2100 fent->linetab_len;
2102 * Figure out the offset of the next entry.
2103 * There is a fixed part of the record and a variable
2104 * length filename which we must also skip past.
2106 offset += ((unsigned int) &fent->filename - (unsigned int) fent)
2107 + strlen(fent->filename) + 1;
2108 offset += strlen(buffer+offset) + 1;
2109 offset = (offset + 3) & ~3;
2115 * Two different magic numbers used as dates.
2116 * These indicate the 'type' table.
2118 if( *pnt == 19950410
2119 || *pnt == 19951122 )
2121 DEBUG_ParseTypeTable(buffer, filelist[i].record_len);
2122 continue;
2126 * This is something we really want to look at, since it contains
2127 * real debug info. Anything that doesn't match this can be
2128 * ignored for now.
2130 if( *pnt == 1 )
2133 * First, snag the line table, if we have one. This always
2134 * occurs at the end of the record, so we take the linetab
2135 * offset as the end of the normal part of the record.
2137 linetab = NULL;
2138 if( filelist[i].linetab_len != 0 )
2140 linetab = DEBUG_SnarfLinetab(buffer + filelist[i].linetab_offset,
2141 filelist[i].linetab_len);
2142 DEBUG_SnarfCodeView(deefer, buffer,
2143 filelist[i].linetab_offset,
2144 linetab);
2146 else
2148 DEBUG_SnarfCodeView(deefer, buffer,
2149 filelist[i].record_len,
2150 linetab);
2152 continue;
2157 * Finally, process the global symbol table itself. There isn't
2158 * a line number component to this, so we just toss everything
2159 * into the mix and it all should work out.
2161 if( gsym_record != 0 )
2163 DEBUG_SnarfCodeView(deefer, gsymtab - sizeof(int),
2164 filelist[gsym_record].record_len,
2165 NULL);
2168 leave:
2170 if( gsymtab != NULL )
2172 DBG_free(gsymtab);
2173 gsymtab = NULL;
2176 if( buffer != NULL )
2178 DBG_free(buffer);
2181 if( filelist != NULL )
2183 DBG_free(filelist);
2186 if( addr != (char *) 0xffffffff )
2188 munmap(addr, statbuf.st_size);
2191 if( fd != -1 )
2193 close(fd);
2196 return TRUE;
2200 * Process DBG file which contains debug information.
2202 /* static */
2204 DEBUG_ProcessDBGFile(struct deferred_debug_info * deefer, char * filename)
2206 char * addr = (char *) 0xffffffff;
2207 char * codeview;
2208 struct CV4_DirHead * codeview_dir;
2209 struct CV4_DirEnt * codeview_dent;
2210 PIMAGE_DEBUG_DIRECTORY dbghdr;
2211 struct deferred_debug_info deefer2;
2212 int fd = -1;
2213 int i;
2214 int j;
2215 struct codeview_linetab_hdr * linetab;
2216 int nsect;
2217 PIMAGE_SEPARATE_DEBUG_HEADER pdbg = NULL;
2218 IMAGE_SECTION_HEADER * sectp;
2219 struct stat statbuf;
2220 int status;
2221 char dbg_file[MAX_PATHNAME_LEN];
2223 LocateDebugInfoFile(filename, dbg_file);
2224 status = stat(dbg_file, &statbuf);
2225 if( status == -1 )
2227 fprintf(stderr, "-Unable to open .DBG file %s\n", dbg_file);
2228 goto leave;
2232 * Now open the file, so that we can mmap() it.
2234 fd = open(dbg_file, O_RDONLY);
2235 if( fd == -1 )
2237 fprintf(stderr, "Unable to open .DBG file %s\n", dbg_file);
2238 goto leave;
2243 * Now mmap() the file.
2245 addr = mmap(0, statbuf.st_size, PROT_READ,
2246 MAP_PRIVATE, fd, 0);
2247 if( addr == (char *) 0xffffffff )
2249 fprintf(stderr, "Unable to mmap .DBG file %s\n", dbg_file);
2250 goto leave;
2253 pdbg = (PIMAGE_SEPARATE_DEBUG_HEADER) addr;
2255 if( pdbg->TimeDateStamp != deefer->dbgdir->TimeDateStamp )
2257 fprintf(stderr, "Warning - %s has incorrect internal timestamp\n",
2258 dbg_file);
2259 /* goto leave; */
2261 Well, sometimes this happens to DBG files which ARE REALLY the right .DBG
2262 files but nonetheless this check fails. Anyway, WINDBG (debugger for
2263 Windows by Microsoft) loads debug symbols which have incorrect timestamps.
2267 fprintf(stderr, "Processing symbols from %s...\n", dbg_file);
2269 dbghdr = (PIMAGE_DEBUG_DIRECTORY) ( addr + sizeof(*pdbg)
2270 + pdbg->NumberOfSections * sizeof(IMAGE_SECTION_HEADER)
2271 + pdbg->ExportedNamesSize);
2273 sectp = (PIMAGE_SECTION_HEADER) ((char *) pdbg + sizeof(*pdbg));
2274 nsect = pdbg->NumberOfSections;
2276 for( i=0; i < pdbg->DebugDirectorySize / sizeof(*pdbg); i++, dbghdr++ )
2278 switch(dbghdr->Type)
2280 case IMAGE_DEBUG_TYPE_COFF:
2282 * Dummy up a deferred debug header to handle the
2283 * COFF stuff embedded within the DBG file.
2285 memset((char *) &deefer2, 0, sizeof(deefer2));
2286 deefer2.dbg_info = (addr + dbghdr->PointerToRawData);
2287 deefer2.dbg_size = dbghdr->SizeOfData;
2288 deefer2.load_addr = deefer->load_addr;
2290 DEBUG_ProcessCoff(&deefer2);
2291 break;
2292 case IMAGE_DEBUG_TYPE_CODEVIEW:
2294 * This is the older format by which codeview stuff is
2295 * stored, known as the 'NB09' format. Newer executables
2296 * and dlls created by VC++ use PDB files instead, which
2297 * have lots of internal similarities, but the overall
2298 * format and structure is quite different.
2300 codeview = (addr + dbghdr->PointerToRawData);
2303 * The first thing in the codeview section should be
2304 * an 'NB09' identifier. As a sanity check, make sure
2305 * it is there.
2307 if( *((unsigned int*) codeview) != 0x3930424e )
2309 break;
2313 * Next we need to find the directory. This is easy too.
2315 codeview_dir = (struct CV4_DirHead *)
2316 (codeview + ((unsigned int*) codeview)[1]);
2319 * Some more sanity checks. Make sure that everything
2320 * is as we expect it.
2322 if( codeview_dir->next_offset != 0
2323 || codeview_dir->dhsize != sizeof(*codeview_dir)
2324 || codeview_dir->desize != sizeof(*codeview_dent) )
2326 break;
2328 codeview_dent = (struct CV4_DirEnt *) (codeview_dir + 1);
2330 for(j=0; j < codeview_dir->ndir; j++, codeview_dent++)
2332 if( codeview_dent->subsect_number == sstAlignSym )
2335 * Check the previous entry. If it is a
2336 * sstSrcModule, it contains the line number
2337 * info for this file.
2339 linetab = NULL;
2340 if( codeview_dent[1].module_number == codeview_dent[0].module_number
2341 && codeview_dent[1].subsect_number == sstSrcModule )
2343 linetab = DEBUG_SnarfLinetab(
2344 codeview + codeview_dent[1].offset,
2345 codeview_dent[1].size);
2348 if( codeview_dent[-1].module_number == codeview_dent[0].module_number
2349 && codeview_dent[-1].subsect_number == sstSrcModule )
2351 linetab = DEBUG_SnarfLinetab(
2352 codeview + codeview_dent[-1].offset,
2353 codeview_dent[-1].size);
2356 * Now process the CV stuff.
2358 DEBUG_SnarfCodeView(deefer,
2359 codeview + codeview_dent->offset,
2360 codeview_dent->size,
2361 linetab);
2365 break;
2366 default:
2367 break;
2370 leave:
2372 if( addr != (char *) 0xffffffff )
2374 munmap(addr, statbuf.st_size);
2377 if( fd != -1 )
2379 close(fd);
2382 return TRUE;
2386 DEBUG_ProcessDeferredDebug()
2388 struct deferred_debug_info * deefer;
2389 struct CodeViewDebug * cvd;
2390 struct MiscDebug * misc;
2391 char * filename;
2392 int last_proc = -1;
2393 int need_print =0;
2394 int sts;
2396 for(deefer = dbglist; deefer; deefer = deefer->next)
2398 if( deefer->status != DF_STATUS_NEW )
2400 continue;
2403 if( last_proc != deefer->dbg_index )
2405 if (!need_print)
2407 fprintf(stderr, "DeferredDebug for:");
2408 need_print=1;
2410 fprintf(stderr, " %s",deefer->module_name);
2411 last_proc = deefer->dbg_index;
2414 switch(deefer->dbgdir->Type)
2416 case IMAGE_DEBUG_TYPE_COFF:
2418 * Standard COFF debug information that VC++ adds when you
2419 * use /debugtype:both with the linker.
2421 #if 0
2422 fprintf(stderr, "Processing COFF symbols...\n");
2423 #endif
2424 sts = DEBUG_ProcessCoff(deefer);
2425 break;
2426 case IMAGE_DEBUG_TYPE_CODEVIEW:
2428 * This is a pointer to a PDB file of some sort.
2430 cvd = (struct CodeViewDebug *) deefer->dbg_info;
2432 if( strcmp(cvd->cv_nbtype, "NB10") != 0 )
2435 * Whatever this is, we don't know how to deal with
2436 * it yet.
2438 sts = FALSE;
2439 break;
2441 sts = DEBUG_ProcessPDBFile(deefer, cvd->cv_name);
2442 #if 0
2443 fprintf(stderr, "Processing PDB file %s\n", cvd->cv_name);
2444 #endif
2445 break;
2446 case IMAGE_DEBUG_TYPE_MISC:
2448 * A pointer to a .DBG file of some sort. These files
2449 * can contain either CV4 or COFF information. Open
2450 * the file, and try to do the right thing with it.
2452 misc = (struct MiscDebug *) deefer->dbg_info;
2454 filename = strrchr((char *) &misc->Data, '.');
2457 * Ignore the file if it doesn't have a .DBG extension.
2459 if( (filename == NULL)
2460 || ( (strcmp(filename, ".dbg") != 0)
2461 && (strcmp(filename, ".DBG") != 0)) )
2463 sts = FALSE;
2464 break;
2467 filename = (char *) &misc->Data;
2470 * Do the dirty deed...
2472 sts = DEBUG_ProcessDBGFile(deefer, filename);
2474 break;
2475 default:
2477 * We should never get here...
2479 sts = FALSE;
2480 break;
2482 deefer->status = (sts) ? DF_STATUS_LOADED : DF_STATUS_ERROR;
2485 if(need_print)
2486 fprintf(stderr, "\n");
2487 return TRUE;
2491 /***********************************************************************
2492 * DEBUG_InfoShare
2494 * Display shared libarary information.
2496 void DEBUG_InfoShare(void)
2498 struct deferred_debug_info * deefer;
2500 fprintf(stderr,"Address\t\tModule\tName\n");
2502 for(deefer = dbglist; deefer; deefer = deefer->next)
2504 fprintf(stderr,"0x%8.8x\t(%s)\t%s\n", (unsigned int) deefer->load_addr,
2505 deefer->module ? "Win32" : "ELF", deefer->module_name);