Implemented the PSH_USEICONID/PSH_USEHICON and the PSP_USETITLE
[wine.git] / debugger / msc.c
blob42a200d9a793accdadc53db4c45fb84d6c617f72
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 loaded;
559 struct deferred_debug_info * dbglist = NULL;
562 * A simple macro that tells us whether a given COFF symbol is a
563 * function or not.
565 #define N_TMASK 0x0030
566 #define IMAGE_SYM_DTYPE_FUNCTION 2
567 #define N_BTSHFT 4
568 #define ISFCN(x) (((x) & N_TMASK) == (IMAGE_SYM_DTYPE_FUNCTION << N_BTSHFT))
572 * This is what we are looking for in the COFF symbols.
574 #define IMAGE_SYM_CLASS_EXTERNAL 0x2
575 #define IMAGE_SYM_CLASS_STATIC 0x3
576 #define IMAGE_SYM_CLASS_FILE 0x67
578 static
579 struct datatype * DEBUG_GetCVType(int typeno)
581 struct datatype * dt = NULL;
584 * Convert Codeview type numbers into something we can grok internally.
585 * Numbers < 0x1000 are all fixed builtin types. Numbers from 0x1000 and
586 * up are all user defined (structs, etc).
588 if( typeno < 0x1000 )
590 if( typeno < MAX_BUILTIN_TYPES )
592 dt = cv_basic_types[typeno];
595 else
597 if( typeno - 0x1000 < num_cv_defined_types )
599 dt = cv_defined_types[typeno - 0x1000];
603 return dt;
606 static int
607 DEBUG_ParseTypeTable(char * table, int len)
609 int arr_max;
610 int curr_type;
611 enum debug_type fieldtype;
612 int elem_size;
613 union any_size ptr;
614 union any_size ptr2;
615 struct datatype * subtype;
616 char symname[256];
617 union codeview_type * type;
618 union codeview_type * type2;
619 struct datatype * typeptr;
621 curr_type = 0x1000;
623 ptr.c = (table + 16);
624 while( ptr.c - table < len )
626 type = (union codeview_type *) ptr.c;
628 if( curr_type - 0x1000 >= num_cv_defined_types )
630 num_cv_defined_types += 0x100;
631 cv_defined_types = (struct datatype **) DBG_realloc(cv_defined_types,
632 num_cv_defined_types * sizeof(struct datatype *));
633 memset(cv_defined_types + num_cv_defined_types - 0x100,
635 0x100 * sizeof(struct datatype *));
636 if( cv_defined_types == NULL )
638 return FALSE;
642 switch(type->generic.id)
644 case LF_POINTER:
645 cv_defined_types[curr_type - 0x1000] =
646 DEBUG_FindOrMakePointerType(DEBUG_GetCVType(type->pointer.datatype));
647 break;
648 case LF_ARRAY:
649 if( type->array.arrlen >= 0x8000 )
652 * This is a numeric leaf, I am too lazy to handle this right
653 * now.
655 fprintf(stderr, "Ignoring large numberic leaf.\n");
656 break;
658 if( type->array.namelen != 0 )
660 memset(symname, 0, sizeof(symname));
661 memcpy(symname, type->array.name, type->array.namelen);
662 typeptr = DEBUG_NewDataType(DT_ARRAY, symname);
664 else
666 typeptr = DEBUG_NewDataType(DT_ARRAY, NULL);
668 cv_defined_types[curr_type - 0x1000] = typeptr;
670 subtype = DEBUG_GetCVType(type->array.elemtype);
671 if( (subtype == NULL)
672 || (elem_size = DEBUG_GetObjectSize(subtype)) == 0 )
674 arr_max = 0;
676 else
678 arr_max = type->array.arrlen / DEBUG_GetObjectSize(subtype);
681 DEBUG_SetArrayParams(typeptr, 0, arr_max, subtype);
682 break;
683 case LF_FIELDLIST:
685 * This is where the basic list of fields is defined for
686 * structures and classes.
688 * First, we need to look ahead and see whether we are building
689 * a fieldlist for an enum or a struct.
691 ptr2.i = ptr.i + 1;
692 type2 = (union codeview_type *) ptr2.c;
693 if( type2->member.id == LF_MEMBER )
695 typeptr = DEBUG_NewDataType(DT_STRUCT, NULL);
696 fieldtype = DT_STRUCT;
698 else if( type2->member.id == LF_ENUMERATE )
700 typeptr = DEBUG_NewDataType(DT_ENUM, NULL);
701 fieldtype = DT_ENUM;
703 else
705 break;
708 cv_defined_types[curr_type - 0x1000] = typeptr;
709 while( ptr2.c < (ptr.c + ((type->generic.len + 3) & ~3)) )
711 type2 = (union codeview_type *) ptr2.c;
712 if( type2->member.id == LF_MEMBER && fieldtype == DT_STRUCT )
714 memset(symname, 0, sizeof(symname));
715 memcpy(symname, type2->member.name, type2->member.namelen);
717 subtype = DEBUG_GetCVType(type2->member.type);
718 elem_size = 0;
719 if( subtype != NULL )
721 elem_size = DEBUG_GetObjectSize(subtype);
724 if( type2->member.offset >= 0x8000 )
727 * This is a numeric leaf, I am too lazy to handle this right
728 * now.
730 fprintf(stderr, "Ignoring large numberic leaf.\n");
732 else
734 DEBUG_AddStructElement(typeptr, symname, subtype,
735 type2->member.offset << 3,
736 elem_size << 3);
739 else if( type2->member.id == LF_ENUMERATE && fieldtype == DT_ENUM )
741 memset(symname, 0, sizeof(symname));
742 memcpy(symname, type2->enumerate.name, type2->enumerate.namelen);
744 if( type2->enumerate.value >= 0x8000 )
747 * This is a numeric leaf, I am too lazy to handle this right
748 * now.
750 fprintf(stderr, "Ignoring large numberic leaf.\n");
752 else
754 DEBUG_AddStructElement(typeptr, symname, NULL,
755 type2->enumerate.value, 0);
758 else
761 * Something else I have never seen before. Either wrong type of
762 * object in the fieldlist, or some other problem which I wouldn't
763 * really know how to handle until it came up.
765 fprintf(stderr, "Unexpected entry in fieldlist\n");
766 break;
770 ptr2.c += ((type2->member.namelen + 9 + 3) & ~3);
772 break;
773 case LF_STRUCTURE:
774 case LF_CLASS:
775 if( type->structure.structlen >= 0x8000 )
778 * This is a numeric leaf, I am too lazy to handle this right
779 * now.
781 fprintf(stderr, "Ignoring large numberic leaf.\n");
782 break;
784 memset(symname, 0, sizeof(symname));
785 memcpy(symname, type->structure.name, type->structure.namelen);
786 if( strcmp(symname, "__unnamed") == 0 )
788 typeptr = DEBUG_NewDataType(DT_STRUCT, NULL);
790 else
792 typeptr = DEBUG_NewDataType(DT_STRUCT, symname);
794 cv_defined_types[curr_type - 0x1000] = typeptr;
797 * Now copy the relevant bits from the fieldlist that we specified.
799 subtype = DEBUG_GetCVType(type->structure.fieldlist);
801 if( subtype != NULL )
803 DEBUG_SetStructSize(typeptr, type->structure.structlen);
804 DEBUG_CopyFieldlist(typeptr, subtype);
806 break;
807 case LF_UNION:
808 if( type->t_union.un_len >= 0x8000 )
811 * This is a numeric leaf, I am too lazy to handle this right
812 * now.
814 fprintf(stderr, "Ignoring large numberic leaf.\n");
815 break;
817 memset(symname, 0, sizeof(symname));
818 memcpy(symname, type->t_union.name, type->t_union.namelen);
820 if( strcmp(symname, "__unnamed") == 0 )
822 typeptr = DEBUG_NewDataType(DT_STRUCT, NULL);
824 else
826 typeptr = DEBUG_NewDataType(DT_STRUCT, symname);
829 cv_defined_types[curr_type - 0x1000] = typeptr;
832 * Now copy the relevant bits from the fieldlist that we specified.
834 subtype = DEBUG_GetCVType(type->t_union.field);
836 if( subtype != NULL )
838 DEBUG_SetStructSize(typeptr, type->t_union.un_len);
839 DEBUG_CopyFieldlist(typeptr, subtype);
841 break;
842 case LF_BITFIELD:
843 typeptr = DEBUG_NewDataType(DT_BITFIELD, NULL);
844 cv_defined_types[curr_type - 0x1000] = typeptr;
845 DEBUG_SetBitfieldParams(typeptr, type->bitfield.bitoff,
846 type->bitfield.nbits,
847 DEBUG_GetCVType(type->bitfield.type));
848 break;
849 case LF_ENUMERATION:
850 memset(symname, 0, sizeof(symname));
851 memcpy(symname, type->enumeration.name, type->enumeration.namelen);
852 typeptr = DEBUG_NewDataType(DT_ENUM, symname);
853 cv_defined_types[curr_type - 0x1000] = typeptr;
856 * Now copy the relevant bits from the fieldlist that we specified.
858 subtype = DEBUG_GetCVType(type->enumeration.field);
860 if( subtype != NULL )
862 DEBUG_CopyFieldlist(typeptr, subtype);
864 break;
865 case LF_DIMARRAY:
866 default:
867 break;
869 curr_type++;
870 ptr.c += (type->generic.len + 3) & ~3;
873 return TRUE;
876 void
877 DEBUG_InitCVDataTypes()
880 * These are the common builtin types that are used by VC++.
882 cv_basic_types[T_NOTYPE] = NULL;
883 cv_basic_types[T_ABS] = NULL;
884 cv_basic_types[T_VOID] = DEBUG_NewDataType(DT_BASIC, "void");
885 cv_basic_types[T_CHAR] = DEBUG_NewDataType(DT_BASIC, "char");
886 cv_basic_types[T_SHORT] = DEBUG_NewDataType(DT_BASIC, "short int");
887 cv_basic_types[T_LONG] = DEBUG_NewDataType(DT_BASIC, "long int");
888 cv_basic_types[T_QUAD] = DEBUG_NewDataType(DT_BASIC, "long long int");
889 cv_basic_types[T_UCHAR] = DEBUG_NewDataType(DT_BASIC, "unsigned char");
890 cv_basic_types[T_USHORT] = DEBUG_NewDataType(DT_BASIC, "short unsigned int");
891 cv_basic_types[T_ULONG] = DEBUG_NewDataType(DT_BASIC, "long unsigned int");
892 cv_basic_types[T_UQUAD] = DEBUG_NewDataType(DT_BASIC, "long long unsigned int");
893 cv_basic_types[T_REAL32] = DEBUG_NewDataType(DT_BASIC, "float");
894 cv_basic_types[T_REAL64] = DEBUG_NewDataType(DT_BASIC, "double");
895 cv_basic_types[T_RCHAR] = DEBUG_NewDataType(DT_BASIC, "char");
896 cv_basic_types[T_WCHAR] = DEBUG_NewDataType(DT_BASIC, "short");
897 cv_basic_types[T_INT4] = DEBUG_NewDataType(DT_BASIC, "int");
898 cv_basic_types[T_UINT4] = DEBUG_NewDataType(DT_BASIC, "unsigned int");
900 cv_basic_types[T_32PVOID] = DEBUG_FindOrMakePointerType(cv_basic_types[T_VOID]);
901 cv_basic_types[T_32PCHAR] = DEBUG_FindOrMakePointerType(cv_basic_types[T_CHAR]);
902 cv_basic_types[T_32PSHORT] = DEBUG_FindOrMakePointerType(cv_basic_types[T_SHORT]);
903 cv_basic_types[T_32PLONG] = DEBUG_FindOrMakePointerType(cv_basic_types[T_LONG]);
904 cv_basic_types[T_32PQUAD] = DEBUG_FindOrMakePointerType(cv_basic_types[T_QUAD]);
905 cv_basic_types[T_32PUCHAR] = DEBUG_FindOrMakePointerType(cv_basic_types[T_UCHAR]);
906 cv_basic_types[T_32PUSHORT] = DEBUG_FindOrMakePointerType(cv_basic_types[T_USHORT]);
907 cv_basic_types[T_32PULONG] = DEBUG_FindOrMakePointerType(cv_basic_types[T_ULONG]);
908 cv_basic_types[T_32PUQUAD] = DEBUG_FindOrMakePointerType(cv_basic_types[T_UQUAD]);
909 cv_basic_types[T_32PREAL32] = DEBUG_FindOrMakePointerType(cv_basic_types[T_REAL32]);
910 cv_basic_types[T_32PREAL64] = DEBUG_FindOrMakePointerType(cv_basic_types[T_REAL64]);
911 cv_basic_types[T_32PRCHAR] = DEBUG_FindOrMakePointerType(cv_basic_types[T_RCHAR]);
912 cv_basic_types[T_32PWCHAR] = DEBUG_FindOrMakePointerType(cv_basic_types[T_WCHAR]);
913 cv_basic_types[T_32PINT4] = DEBUG_FindOrMakePointerType(cv_basic_types[T_INT4]);
914 cv_basic_types[T_32PUINT4] = DEBUG_FindOrMakePointerType(cv_basic_types[T_UINT4]);
918 * In this function, we keep track of deferred debugging information
919 * that we may need later if we were to need to use the internal debugger.
920 * We don't fully process it here for performance reasons.
923 DEBUG_RegisterDebugInfo( HMODULE hModule, const char *module_name)
925 int has_codeview = FALSE;
926 int rtn = FALSE;
927 int orig_size;
928 PIMAGE_DEBUG_DIRECTORY dbgptr;
929 u_long v_addr, size;
930 PIMAGE_NT_HEADERS nth = PE_HEADER(hModule);
932 size = nth->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].Size;
933 if (size) {
934 v_addr = nth->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress;
935 dbgptr = (PIMAGE_DEBUG_DIRECTORY) (hModule + v_addr);
936 orig_size = size;
937 for(; size >= sizeof(*dbgptr); size -= sizeof(*dbgptr), dbgptr++ )
939 switch(dbgptr->Type)
941 case IMAGE_DEBUG_TYPE_CODEVIEW:
942 case IMAGE_DEBUG_TYPE_MISC:
943 has_codeview = TRUE;
944 break;
948 size = orig_size;
949 dbgptr = (PIMAGE_DEBUG_DIRECTORY) (hModule + v_addr);
950 for(; size >= sizeof(*dbgptr); size -= sizeof(*dbgptr), dbgptr++ )
952 switch(dbgptr->Type)
954 case IMAGE_DEBUG_TYPE_COFF:
956 * If we have both codeview and COFF debug info, ignore the
957 * coff debug info as it would just confuse us, and it is
958 * less complete.
960 * FIXME - this is broken - if we cannot find the PDB file, then
961 * we end up with no debugging info at all. In this case, we
962 * should use the COFF info as a backup.
964 if( has_codeview )
966 break;
968 case IMAGE_DEBUG_TYPE_CODEVIEW:
969 case IMAGE_DEBUG_TYPE_MISC:
971 * This is usually an indirection to a .DBG file.
972 * This is similar to (but a slightly older format) from the
973 * PDB file.
975 * First check to see if the image was 'stripped'. If so, it
976 * means that this entry points to a .DBG file. Otherwise,
977 * it just points to itself, and we can ignore this.
985 if( (dbgptr->Type != IMAGE_DEBUG_TYPE_MISC) ||
986 (PE_HEADER(hModule)->FileHeader.Characteristics & IMAGE_FILE_DEBUG_STRIPPED) != 0 )
988 char fn[PATH_MAX];
989 int fd = -1;
990 DOS_FULL_NAME full_name;
991 struct deferred_debug_info* deefer = (struct deferred_debug_info *) DBG_alloc(sizeof(*deefer));
993 deefer->module = hModule;
994 deefer->load_addr = (char *)hModule;
997 * Read the important bits. What we do after this depends
998 * upon the type, but this is always enough so we are able
999 * to proceed if we know what we need to do next.
1001 /* basically, the PE loader maps all sections (data, resources...), but doesn't map
1002 * the DataDirectory array's content. One its entry contains the *beloved*
1003 * debug information. (Note the DataDirectory is mapped, not its content)
1006 if (GetModuleFileNameA(hModule, fn, sizeof(fn)) > 0 &&
1007 DOSFS_GetFullName(fn, TRUE, &full_name) &&
1008 (fd = open(full_name.long_name, O_RDONLY)) > 0)
1010 deefer->dbg_info = mmap(NULL, dbgptr->SizeOfData,
1011 PROT_READ, MAP_PRIVATE, fd, dbgptr->PointerToRawData);
1012 close(fd);
1013 if( deefer->dbg_info == (char *) 0xffffffff )
1015 DBG_free(deefer);
1016 break;
1019 else
1021 DBG_free(deefer);
1022 fprintf(stderr, " (not mapped: fn=%s, lfn=%s, fd=%d)", fn, full_name.long_name, fd);
1023 break;
1025 deefer->dbg_size = dbgptr->SizeOfData;
1026 deefer->dbgdir = dbgptr;
1027 deefer->next = dbglist;
1028 deefer->loaded = FALSE;
1029 deefer->dbg_index = DEBUG_next_index;
1030 deefer->module_name = DBG_strdup(module_name);
1032 deefer->sectp = PE_SECTIONS(hModule);
1033 deefer->nsect = PE_HEADER(hModule)->FileHeader.NumberOfSections;
1035 dbglist = deefer;
1037 break;
1038 #if 0
1039 default:
1040 #endif
1043 DEBUG_next_index++;
1045 /* look for .stabs/.stabstr sections */
1047 PIMAGE_SECTION_HEADER pe_seg = PE_SECTIONS(hModule);
1048 int i,stabsize=0,stabstrsize=0;
1049 unsigned int stabs=0,stabstr=0;
1051 for (i=0;i<nth->FileHeader.NumberOfSections;i++) {
1052 if (!strcasecmp(pe_seg[i].Name,".stab")) {
1053 stabs = pe_seg[i].VirtualAddress;
1054 stabsize = pe_seg[i].SizeOfRawData;
1056 if (!strncasecmp(pe_seg[i].Name,".stabstr",8)) {
1057 stabstr = pe_seg[i].VirtualAddress;
1058 stabstrsize = pe_seg[i].SizeOfRawData;
1061 if (stabstrsize && stabsize) {
1062 #ifdef _WE_SUPPORT_THE_STAB_TYPES_USED_BY_MINGW_TOO
1063 /* Won't work currently, since MINGW32 uses some special typedefs
1064 * which we do not handle yet. Support for them is a bit difficult.
1066 DEBUG_ParseStabs(hModule,0,stabs,stabsize,stabstr,stabstrsize);
1067 #endif
1068 fprintf(stderr,"(stabs not loaded)");
1071 return (rtn);
1075 * ELF modules are also entered into the list - this is so that we
1076 * can make 'info shared' types of displays possible.
1079 DEBUG_RegisterELFDebugInfo(int load_addr, u_long size, char * name)
1081 struct deferred_debug_info * deefer;
1083 deefer = (struct deferred_debug_info *) DBG_alloc(sizeof(*deefer));
1084 deefer->module = 0;
1087 * Read the important bits. What we do after this depends
1088 * upon the type, but this is always enough so we are able
1089 * to proceed if we know what we need to do next.
1091 deefer->dbg_size = size;
1092 deefer->dbg_info = (char *) NULL;
1094 deefer->load_addr = (char *) load_addr;
1095 deefer->dbgdir = NULL;
1096 deefer->next = dbglist;
1097 deefer->loaded = TRUE;
1098 deefer->dbg_index = DEBUG_next_index;
1099 deefer->module_name = DBG_strdup(name);
1100 dbglist = deefer;
1102 DEBUG_next_index++;
1104 return (TRUE);
1110 * Process COFF debugging information embedded in a Win32 application.
1113 static
1115 DEBUG_ProcessCoff(struct deferred_debug_info * deefer)
1117 struct CoffAuxSection * aux;
1118 struct CoffDebug * coff;
1119 struct CoffFiles * coff_files = NULL;
1120 struct CoffLinenum * coff_linetab;
1121 char * coff_strtab;
1122 struct CoffSymbol * coff_sym;
1123 struct CoffSymbol * coff_symbol;
1124 struct CoffFiles * curr_file = NULL;
1125 int i;
1126 int j;
1127 int k;
1128 struct CoffLinenum * linepnt;
1129 int linetab_indx;
1130 char namebuff[9];
1131 char * nampnt;
1132 int naux;
1133 DBG_ADDR new_addr;
1134 int nfiles = 0;
1135 int nfiles_alloc = 0;
1136 struct CoffFiles orig_file;
1137 int rtn = FALSE;
1138 char * this_file = NULL;
1140 coff = (struct CoffDebug *) deefer->dbg_info;
1142 coff_symbol = (struct CoffSymbol *) ((unsigned int) coff + coff->SymbolOffset);
1143 coff_linetab = (struct CoffLinenum *) ((unsigned int) coff + coff->LinenumberOffset);
1144 coff_strtab = (char *) ((unsigned int) coff_symbol + 18*coff->N_Sym);
1146 linetab_indx = 0;
1148 for(i=0; i < coff->N_Sym; i++ )
1151 * We do this because some compilers (i.e. gcc) incorrectly
1152 * pad the structure up to a 4 byte boundary. The structure
1153 * is really only 18 bytes long, so we have to manually make sure
1154 * we get it right.
1156 * FIXME - there must be a way to have autoconf figure out the
1157 * correct compiler option for this. If it is always gcc, that
1158 * makes life simpler, but I don't want to force this.
1160 coff_sym = (struct CoffSymbol *) ((unsigned int) coff_symbol + 18*i);
1161 naux = coff_sym->NumberOfAuxSymbols;
1163 if( coff_sym->StorageClass == IMAGE_SYM_CLASS_FILE )
1165 if( nfiles + 1 >= nfiles_alloc )
1167 nfiles_alloc += 10;
1168 coff_files = (struct CoffFiles *) DBG_realloc(coff_files,
1169 nfiles_alloc * sizeof(struct CoffFiles));
1171 curr_file = coff_files + nfiles;
1172 nfiles++;
1173 curr_file->startaddr = 0xffffffff;
1174 curr_file->endaddr = 0;
1175 curr_file->filename = ((char *) coff_sym) + 18;
1176 curr_file->linetab_offset = -1;
1177 curr_file->linecnt = 0;
1178 curr_file->entries = NULL;
1179 curr_file->neps = curr_file->neps_alloc = 0;
1180 #if 0
1181 fprintf(stderr,"New file %s\n", curr_file->filename);
1182 #endif
1183 i += naux;
1184 continue;
1188 * This guy marks the size and location of the text section
1189 * for the current file. We need to keep track of this so
1190 * we can figure out what file the different global functions
1191 * go with.
1193 if( (coff_sym->StorageClass == IMAGE_SYM_CLASS_STATIC)
1194 && (naux != 0)
1195 && (coff_sym->Type == 0)
1196 && (coff_sym->SectionNumber == 1) )
1198 aux = (struct CoffAuxSection *) ((unsigned int) coff_sym + 18);
1200 if( curr_file->linetab_offset != -1 )
1202 #if 0
1203 fprintf(stderr, "Duplicating sect from %s: %x %x %x %d %d\n",
1204 curr_file->filename,
1205 aux->Length,
1206 aux->NumberOfRelocations,
1207 aux->NumberOfLinenumbers,
1208 aux->Number,
1209 aux->Selection);
1210 fprintf(stderr, "More sect %d %x %d %d %d\n",
1211 coff_sym->SectionNumber,
1212 coff_sym->Value,
1213 coff_sym->Type,
1214 coff_sym->StorageClass,
1215 coff_sym->NumberOfAuxSymbols);
1216 #endif
1219 * Save this so we can copy bits from it.
1221 orig_file = *curr_file;
1224 * Duplicate the file entry. We have no way to describe
1225 * multiple text sections in our current way of handling things.
1227 if( nfiles + 1 >= nfiles_alloc )
1229 nfiles_alloc += 10;
1230 coff_files = (struct CoffFiles *) DBG_realloc(coff_files,
1231 nfiles_alloc * sizeof(struct CoffFiles));
1233 curr_file = coff_files + nfiles;
1234 nfiles++;
1235 curr_file->startaddr = 0xffffffff;
1236 curr_file->endaddr = 0;
1237 curr_file->filename = orig_file.filename;
1238 curr_file->linetab_offset = -1;
1239 curr_file->linecnt = 0;
1240 curr_file->entries = NULL;
1241 curr_file->neps = curr_file->neps_alloc = 0;
1243 #if 0
1244 else
1246 fprintf(stderr, "New text sect from %s: %x %x %x %d %d\n",
1247 curr_file->filename,
1248 aux->Length,
1249 aux->NumberOfRelocations,
1250 aux->NumberOfLinenumbers,
1251 aux->Number,
1252 aux->Selection);
1254 #endif
1256 if( curr_file->startaddr > coff_sym->Value )
1258 curr_file->startaddr = coff_sym->Value;
1261 if( curr_file->startaddr > coff_sym->Value )
1263 curr_file->startaddr = coff_sym->Value;
1266 if( curr_file->endaddr < coff_sym->Value + aux->Length )
1268 curr_file->endaddr = coff_sym->Value + aux->Length;
1271 curr_file->linetab_offset = linetab_indx;
1272 curr_file->linecnt = aux->NumberOfLinenumbers;
1273 linetab_indx += aux->NumberOfLinenumbers;
1274 i += naux;
1275 continue;
1278 if( (coff_sym->StorageClass == IMAGE_SYM_CLASS_STATIC)
1279 && (naux == 0)
1280 && (coff_sym->SectionNumber == 1) )
1283 * This is a normal static function when naux == 0.
1284 * Just register it. The current file is the correct
1285 * one in this instance.
1287 if( coff_sym->N.Name.NotLong )
1289 memcpy(namebuff, coff_sym->N.ShortName, 8);
1290 namebuff[8] = '\0';
1291 nampnt = &namebuff[0];
1293 else
1295 nampnt = coff_strtab + coff_sym->N.Name.StrTaboff;
1298 if( nampnt[0] == '_' )
1300 nampnt++;
1303 new_addr.seg = 0;
1304 new_addr.off = (int) (deefer->load_addr + coff_sym->Value);
1306 if( curr_file->neps + 1 >= curr_file->neps_alloc )
1308 curr_file->neps_alloc += 10;
1309 curr_file->entries = (struct name_hash **)
1310 DBG_realloc(curr_file->entries,
1311 curr_file->neps_alloc * sizeof(struct name_hash *));
1313 #if 0
1314 fprintf(stderr,"\tAdding static symbol %s\n", nampnt);
1315 #endif
1316 curr_file->entries[curr_file->neps++] =
1317 DEBUG_AddSymbol( nampnt, &new_addr, this_file, SYM_WIN32 );
1318 i += naux;
1319 continue;
1322 if( (coff_sym->StorageClass == IMAGE_SYM_CLASS_EXTERNAL)
1323 && ISFCN(coff_sym->Type)
1324 && (coff_sym->SectionNumber > 0) )
1326 if( coff_sym->N.Name.NotLong )
1328 memcpy(namebuff, coff_sym->N.ShortName, 8);
1329 namebuff[8] = '\0';
1330 nampnt = &namebuff[0];
1332 else
1334 nampnt = coff_strtab + coff_sym->N.Name.StrTaboff;
1338 if( nampnt[0] == '_' )
1340 nampnt++;
1343 new_addr.seg = 0;
1344 new_addr.off = (int) (deefer->load_addr + coff_sym->Value);
1346 #if 0
1347 fprintf(stderr, "%d: %x %s\n", i, new_addr.off, nampnt);
1349 fprintf(stderr,"\tAdding global symbol %s\n", nampnt);
1350 #endif
1353 * Now we need to figure out which file this guy belongs to.
1355 this_file = NULL;
1356 for(j=0; j < nfiles; j++)
1358 if( coff_files[j].startaddr <= coff_sym->Value
1359 && coff_files[j].endaddr > coff_sym->Value )
1361 this_file = coff_files[j].filename;
1362 break;
1365 if( coff_files[j].neps + 1 >= coff_files[j].neps_alloc )
1367 coff_files[j].neps_alloc += 10;
1368 coff_files[j].entries = (struct name_hash **)
1369 DBG_realloc(coff_files[j].entries,
1370 coff_files[j].neps_alloc * sizeof(struct name_hash *));
1372 coff_files[j].entries[coff_files[j].neps++] =
1373 DEBUG_AddSymbol( nampnt, &new_addr, this_file, SYM_WIN32 );
1374 i += naux;
1375 continue;
1378 if( (coff_sym->StorageClass == IMAGE_SYM_CLASS_EXTERNAL)
1379 && (coff_sym->SectionNumber > 0) )
1382 * Similar to above, but for the case of data symbols.
1383 * These aren't treated as entrypoints.
1385 if( coff_sym->N.Name.NotLong )
1387 memcpy(namebuff, coff_sym->N.ShortName, 8);
1388 namebuff[8] = '\0';
1389 nampnt = &namebuff[0];
1391 else
1393 nampnt = coff_strtab + coff_sym->N.Name.StrTaboff;
1397 if( nampnt[0] == '_' )
1399 nampnt++;
1402 new_addr.seg = 0;
1403 new_addr.off = (int) (deefer->load_addr + coff_sym->Value);
1405 #if 0
1406 fprintf(stderr, "%d: %x %s\n", i, new_addr.off, nampnt);
1408 fprintf(stderr,"\tAdding global data symbol %s\n", nampnt);
1409 #endif
1412 * Now we need to figure out which file this guy belongs to.
1414 DEBUG_AddSymbol( nampnt, &new_addr, NULL, SYM_WIN32 );
1415 i += naux;
1416 continue;
1419 if( (coff_sym->StorageClass == IMAGE_SYM_CLASS_STATIC)
1420 && (naux == 0) )
1423 * Ignore these. They don't have anything to do with
1424 * reality.
1426 i += naux;
1427 continue;
1430 #if 0
1431 fprintf(stderr,"Skipping unknown entry %d %d %d\n", coff_sym->StorageClass,
1432 coff_sym->SectionNumber, naux);
1433 #endif
1436 * For now, skip past the aux entries.
1438 i += naux;
1443 * OK, we now should have a list of files, and we should have a list
1444 * of entrypoints. We need to sort the entrypoints so that we are
1445 * able to tie the line numbers with the given functions within the
1446 * file.
1448 if( coff_files != NULL )
1450 for(j=0; j < nfiles; j++)
1452 if( coff_files[j].entries != NULL )
1454 qsort(coff_files[j].entries, coff_files[j].neps,
1455 sizeof(struct name_hash *), DEBUG_cmp_sym);
1460 * Now pick apart the line number tables, and attach the entries
1461 * to the given functions.
1463 for(j=0; j < nfiles; j++)
1465 i = 0;
1466 if( coff_files[j].neps != 0 )
1467 for(k=0; k < coff_files[j].linecnt; k++)
1470 * Another monstrosity caused by the fact that we are using
1471 * a 6 byte structure, and gcc wants to pad structures to 4 byte
1472 * boundaries. Otherwise we could just index into an array.
1474 linepnt = (struct CoffLinenum *)
1475 ((unsigned int) coff_linetab +
1476 6*(coff_files[j].linetab_offset + k));
1478 * If we have spilled onto the next entrypoint, then
1479 * bump the counter..
1481 while(TRUE)
1483 if (i+1 >= coff_files[j].neps) break;
1484 DEBUG_GetSymbolAddr(coff_files[j].entries[i+1], &new_addr);
1485 if( (((unsigned int)deefer->load_addr +
1486 linepnt->VirtualAddr) >= new_addr.off) )
1488 i++;
1489 } else break;
1493 * Add the line number. This is always relative to the
1494 * start of the function, so we need to subtract that offset
1495 * first.
1497 DEBUG_GetSymbolAddr(coff_files[j].entries[i], &new_addr);
1498 DEBUG_AddLineNumber(coff_files[j].entries[i],
1499 linepnt->Linenum,
1500 (unsigned int) deefer->load_addr
1501 + linepnt->VirtualAddr
1502 - new_addr.off);
1507 rtn = TRUE;
1509 if( coff_files != NULL )
1511 for(j=0; j < nfiles; j++)
1513 if( coff_files[j].entries != NULL )
1515 DBG_free(coff_files[j].entries);
1518 DBG_free(coff_files);
1521 return (rtn);
1526 * Process a codeview line number table. Digestify the thing so that
1527 * we can easily reference the thing when we process the rest of
1528 * the information.
1530 static struct codeview_linetab_hdr *
1531 DEBUG_SnarfLinetab(char * linetab,
1532 int size)
1534 int file_segcount;
1535 char filename[PATH_MAX];
1536 unsigned int * filetab;
1537 char * fn;
1538 int i;
1539 int k;
1540 struct codeview_linetab_hdr * lt_hdr;
1541 unsigned int * lt_ptr;
1542 int nfile;
1543 int nseg;
1544 union any_size pnt;
1545 union any_size pnt2;
1546 struct startend * start;
1547 int this_seg;
1550 * Now get the important bits.
1552 pnt.c = linetab;
1553 nfile = *pnt.s++;
1554 nseg = *pnt.s++;
1556 filetab = (unsigned int *) pnt.c;
1559 * Now count up the number of segments in the file.
1561 nseg = 0;
1562 for(i=0; i<nfile; i++)
1564 pnt2.c = linetab + filetab[i];
1565 nseg += *pnt2.s;
1569 * Next allocate the header we will be returning.
1570 * There is one header for each segment, so that we can reach in
1571 * and pull bits as required.
1573 lt_hdr = (struct codeview_linetab_hdr *)
1574 DBG_alloc((nseg + 1) * sizeof(*lt_hdr));
1575 if( lt_hdr == NULL )
1577 goto leave;
1580 memset(lt_hdr, 0, sizeof(*lt_hdr) * (nseg+1));
1583 * Now fill the header we will be returning, one for each segment.
1584 * Note that this will basically just contain pointers into the existing
1585 * line table, and we do not actually copy any additional information
1586 * or allocate any additional memory.
1589 this_seg = 0;
1590 for(i=0; i<nfile; i++)
1593 * Get the pointer into the segment information.
1595 pnt2.c = linetab + filetab[i];
1596 file_segcount = *pnt2.s;
1598 pnt2.ui++;
1599 lt_ptr = (unsigned int *) pnt2.c;
1600 start = (struct startend *) (lt_ptr + file_segcount);
1603 * Now snarf the filename for all of the segments for this file.
1605 fn = (unsigned char *) (start + file_segcount);
1606 memset(filename, 0, sizeof(filename));
1607 memcpy(filename, fn + 1, *fn);
1608 fn = DBG_strdup(filename);
1610 for(k = 0; k < file_segcount; k++, this_seg++)
1612 pnt2.c = linetab + lt_ptr[k];
1613 lt_hdr[this_seg].start = start[k].start;
1614 lt_hdr[this_seg].end = start[k].end;
1615 lt_hdr[this_seg].sourcefile = fn;
1616 lt_hdr[this_seg].segno = *pnt2.s++;
1617 lt_hdr[this_seg].nline = *pnt2.s++;
1618 lt_hdr[this_seg].offtab = pnt2.ui;
1619 lt_hdr[this_seg].linetab = (unsigned short *)
1620 (pnt2.ui + lt_hdr[this_seg].nline);
1624 leave:
1626 return lt_hdr;
1630 static int
1631 DEBUG_SnarfCodeView( struct deferred_debug_info * deefer,
1632 char * cv_data,
1633 int size,
1634 struct codeview_linetab_hdr * linetab)
1636 struct name_hash * curr_func = NULL;
1637 struct wine_locals * curr_sym = NULL;
1638 int i;
1639 int j;
1640 int len;
1641 DBG_ADDR new_addr;
1642 int nsect;
1643 union any_size ptr;
1644 IMAGE_SECTION_HEADER * sectp;
1645 union codeview_symbol * sym;
1646 char symname[PATH_MAX];
1647 struct name_hash * thunk_sym = NULL;
1649 ptr.c = cv_data;
1650 nsect = deefer->nsect;
1651 sectp = deefer->sectp;
1654 * Skip over the first word. Don't really know what it means, but
1655 * it is useless.
1657 ptr.ui++;
1660 * Loop over the different types of records and whenever we
1661 * find something we are interested in, record it and move on.
1663 while( ptr.c - cv_data < size )
1665 sym = (union codeview_symbol *) ptr.c;
1667 if( sym->generic.len - sizeof(int) == (ptr.c - cv_data) )
1670 * This happens when we have indirect symbols that VC++ 4.2
1671 * sometimes uses when there isn't a line number table.
1672 * We ignore it - we will process and enter all of the
1673 * symbols in the global symbol table anyways, so there
1674 * isn't much point in keeping track of all of this crap.
1676 break;
1679 memset(symname, 0, sizeof(symname));
1680 switch(sym->generic.id)
1682 case S_GDATA:
1683 case S_LDATA:
1684 case S_PUB:
1686 * First, a couple of sanity checks.
1688 if( sym->data.namelen == 0 )
1690 break;
1693 if( sym->data.seg == 0 || sym->data.seg > nsect )
1695 break;
1699 * Global and local data symbols. We don't associate these
1700 * with any given source file.
1703 memcpy(symname, sym->data.name, sym->data.namelen);
1704 new_addr.seg = 0;
1705 new_addr.type = DEBUG_GetCVType(sym->data.symtype);
1706 new_addr.off = (unsigned int) deefer->load_addr +
1707 sectp[sym->data.seg - 1].VirtualAddress +
1708 sym->data.offset;
1709 DEBUG_AddSymbol( symname, &new_addr, NULL, SYM_WIN32 | SYM_DATA );
1710 break;
1711 case S_THUNK:
1713 * Sort of like a global function, but it just points
1714 * to a thunk, which is a stupid name for what amounts to
1715 * a PLT slot in the normal jargon that everyone else uses.
1717 memcpy(symname, sym->thunk.name, sym->thunk.namelen);
1718 new_addr.seg = 0;
1719 new_addr.type = NULL;
1720 new_addr.off = (unsigned int) deefer->load_addr +
1721 sectp[sym->thunk.segment - 1].VirtualAddress +
1722 sym->thunk.offset;
1723 thunk_sym = DEBUG_AddSymbol( symname, &new_addr, NULL,
1724 SYM_WIN32 | SYM_FUNC);
1725 DEBUG_SetSymbolSize(thunk_sym, sym->thunk.thunk_len);
1726 break;
1727 case S_GPROC:
1728 case S_LPROC:
1730 * Global and static functions.
1732 memcpy(symname, sym->proc.name, sym->proc.namelen);
1733 new_addr.seg = 0;
1734 new_addr.type = DEBUG_GetCVType(sym->proc.proctype);
1735 new_addr.off = (unsigned int) deefer->load_addr +
1736 sectp[sym->proc.segment - 1].VirtualAddress +
1737 sym->proc.offset;
1739 * See if we can find a segment that this goes with. If so,
1740 * it means that we also may have line number information
1741 * for this function.
1743 for(i=0; linetab[i].linetab != NULL; i++)
1745 if( ((unsigned int) deefer->load_addr
1746 + sectp[linetab[i].segno - 1].VirtualAddress
1747 + linetab[i].start <= new_addr.off)
1748 && ((unsigned int) deefer->load_addr
1749 + sectp[linetab[i].segno - 1].VirtualAddress
1750 + linetab[i].end > new_addr.off) )
1752 break;
1756 DEBUG_Normalize(curr_func);
1757 if( linetab[i].linetab == NULL )
1759 curr_func = DEBUG_AddSymbol( symname, &new_addr, NULL,
1760 SYM_WIN32 | SYM_FUNC);
1762 else
1765 * First, create the entry. Then dig through the linetab
1766 * and add whatever line numbers are appropriate for this
1767 * function.
1769 curr_func = DEBUG_AddSymbol( symname, &new_addr,
1770 linetab[i].sourcefile,
1771 SYM_WIN32 | SYM_FUNC);
1772 for(j=0; j < linetab[i].nline; j++)
1774 if( linetab[i].offtab[j] >= sym->proc.offset
1775 && linetab[i].offtab[j] < sym->proc.offset
1776 + sym->proc.proc_len )
1778 DEBUG_AddLineNumber(curr_func, linetab[i].linetab[j],
1779 linetab[i].offtab[j] - sym->proc.offset);
1786 * Add information about where we should set breakpoints
1787 * in this function.
1789 DEBUG_SetSymbolBPOff(curr_func, sym->proc.debug_start);
1790 DEBUG_SetSymbolSize(curr_func, sym->proc.proc_len);
1791 break;
1792 case S_BPREL:
1794 * Function parameters and stack variables.
1796 memcpy(symname, sym->stack.name, sym->stack.namelen);
1797 curr_sym = DEBUG_AddLocal(curr_func,
1799 sym->stack.offset,
1802 symname);
1803 DEBUG_SetLocalSymbolType(curr_sym, DEBUG_GetCVType(sym->stack.symtype));
1805 break;
1806 default:
1807 break;
1811 * Adjust pointer to point to next entry, rounding up to a word
1812 * boundary. MS preserving alignment? Stranger things have
1813 * happened.
1815 if( sym->generic.id == S_PROCREF
1816 || sym->generic.id == S_DATAREF
1817 || sym->generic.id == S_UNKNOWN )
1819 len = (sym->generic.len + 3) & ~3;
1820 len += ptr.c[16] + 1;
1821 ptr.c += (len + 3) & ~3;
1823 else
1825 ptr.c += (sym->generic.len + 3) & ~3;
1829 if( linetab != NULL )
1831 DBG_free(linetab);
1834 return TRUE;
1839 * Process PDB file which contains debug information.
1841 * These are really weird beasts. They are intended to be incrementally
1842 * updated by the incremental linker, and this means that you need to
1843 * be able to remove and add information. Thus the PDB file is sort of
1844 * like a block structured device, with a freelist and lists of extent numbers
1845 * that are used to get the relevant pieces. In all cases seen so far, the
1846 * blocksize is always 0x400 bytes. The header has a field which apparently
1847 * holds the blocksize, so if it ever changes we are safe.
1849 * In general, every time we need to extract something from the pdb file,
1850 * it is easier to copy it into another buffer so we have the information
1851 * in one contiguous block rather than attempt to try and keep track of when
1852 * we need to grab another extent from the pdb file.
1854 * The thing that is a real pain about some MS stuff is that they choose
1855 * data structures which are not representable in C. Thus we have to
1856 * hack around and diddle pointers.
1858 /* static */
1860 DEBUG_ProcessPDBFile(struct deferred_debug_info * deefer, char * full_filename)
1862 char * addr = (char *) 0xffffffff;
1863 unsigned int blocksize;
1864 unsigned int bufflen = 0;
1865 char * buffer = NULL;
1866 unsigned short * extent_table;
1867 int fd = -1;
1868 struct file_ent * fent;
1869 char filename[MAX_PATHNAME_LEN];
1870 struct file_list * filelist = NULL;
1871 unsigned int gsym_record = 0;
1872 char * gsymtab = NULL;
1873 struct filetab_hdr * hd;
1874 int i;
1875 int j;
1876 unsigned int last_extent;
1877 struct codeview_linetab_hdr * linetab;
1878 unsigned int nblocks;
1879 unsigned int npair;
1880 unsigned int offset;
1881 struct codeview_pdb_hdr * pdbhdr;
1882 unsigned int * pnt;
1883 struct stat statbuf;
1884 int status;
1885 unsigned short * table;
1886 char * toc;
1887 unsigned int toc_blocks;
1889 LocateDebugInfoFile(full_filename, filename);
1890 status = stat(filename, &statbuf);
1891 if( status == -1 )
1893 fprintf(stderr, "-Unable to open .PDB file %s\n", filename);
1894 goto leave;
1898 * Now open the file, so that we can mmap() it.
1900 fd = open(filename, O_RDONLY);
1901 if( fd == -1 )
1903 fprintf(stderr, "-Unable to open .DBG file %s\n", filename);
1904 goto leave;
1909 * Now mmap() the file.
1911 addr = mmap(0, statbuf.st_size, PROT_READ,
1912 MAP_PRIVATE, fd, 0);
1913 if( addr == (char *) 0xffffffff )
1915 fprintf(stderr, "-Unable to mmap .DBG file %s\n", filename);
1916 goto leave;
1920 * Now that we have the formalities over and done with, we need
1921 * to find the table of contents for the PDB file.
1923 pdbhdr = (struct codeview_pdb_hdr *) addr;
1924 blocksize = pdbhdr->blocksize;
1925 last_extent = (statbuf.st_size + blocksize - 1) / blocksize;
1928 * The TOC itself isn't always contiguous, so we need to extract a few
1929 * extents from the file to form the TOC.
1931 toc_blocks = (pdbhdr->toc_len + blocksize - 1) / blocksize;
1932 toc = (char *) DBG_alloc(toc_blocks * blocksize);
1933 table = pdbhdr->toc_ext;
1934 for(i=0; i < toc_blocks; i++)
1936 memcpy(toc + blocksize*i, addr + table[i]*blocksize, blocksize);
1940 * Next build our own table which will have the size and extent block
1941 * list for each record in the PDB file.
1943 * The TOC starts out with the number of files. Then it is followed by
1944 * (npair * 2*sizeof(int)) bytes of information, which are pairs of ints.
1945 * The first one is the size of the record (in bytes), and the second one
1946 * is something else which I haven't figured out yet.
1948 pnt = (unsigned int *) toc;
1949 npair = *pnt++;
1950 extent_table = (unsigned short *) ((unsigned int) toc +
1951 npair * 2 * sizeof(int) + sizeof(int));
1954 * Sanity check.
1956 if( sizeof(int) + 2*sizeof(int)*npair > pdbhdr->toc_len )
1958 goto leave;
1961 filelist = (struct file_list *) DBG_alloc(npair * sizeof(*filelist));
1962 if( filelist == NULL )
1964 goto leave;
1966 memset(filelist, 0, npair * sizeof(*filelist));
1968 nblocks = 0;
1969 for(i=0; i < npair; i++)
1971 filelist[i].record_len = pnt[i*2];
1972 filelist[i].nextents = (filelist[i].record_len + blocksize - 1)
1973 / blocksize;
1974 filelist[i].extent_list = extent_table + nblocks;
1975 nblocks += filelist[i].nextents;
1978 * These get filled in later when we parse one of the records.
1980 filelist[i].linetab_offset = 0;
1981 filelist[i].linetab_len = 0;
1985 * OK, now walk through the various records and pick out the bits we
1986 * really want to see. Some of the records are extra special, and
1987 * we need to handle these a little bit differently.
1989 for(i=0; i < npair; i++)
1991 if( filelist[i].record_len == 0xffffffff )
1993 continue;
1997 * Make sure our buffer is large enough to hold the record.
1999 if( bufflen < filelist[i].nextents * blocksize )
2001 bufflen = filelist[i].nextents * blocksize;
2002 buffer = (char *) DBG_realloc(buffer, bufflen);
2006 * Do this just for completeness. It makes debugging easier
2007 * if we have a clean indication of where the record ends.
2009 memset(buffer, 0, filelist[i].nextents * blocksize);
2012 * Next, build the record using the extent list.
2014 for(j=0; j < filelist[i].nextents; j++)
2016 memcpy(buffer + j * blocksize,
2017 addr + filelist[i].extent_list[j] * blocksize,
2018 blocksize);
2021 pnt = (unsigned int *) buffer;
2024 * OK, now figure out what to do with it.
2028 * Always ignore the first entry. It seems to contain a backup copy
2029 * of the TOC (the last time the file was modified??)
2031 if( i == 0 )
2033 continue;
2037 * The second entry as a id block. It contains a magic number
2038 * to identify the compiler, plus it also contains the timestamp
2039 * which must match the timestamp in the executable.
2041 if( i == 1 )
2044 if( ((*pnt != 19950623) && (*pnt != 19950814))
2045 || (filelist[i].record_len != 0x24)
2046 || (pnt[1] != ((struct CodeViewDebug *)(deefer->dbg_info))->cv_timestamp) )
2048 goto leave;
2053 * The third entry contains pointers to the global symbol table,
2054 * plus it also contains additional information about each record
2055 * in the PDB file.
2057 if( i == 3 )
2059 hd = (struct filetab_hdr *) buffer;
2061 gsym_record = hd->gsym_file;
2062 gsymtab = (char *) DBG_alloc(filelist[gsym_record].nextents
2063 * blocksize);
2064 memset(gsymtab, 0, filelist[gsym_record].nextents * blocksize);
2066 for(j=0; j < filelist[gsym_record].nextents; j++)
2068 memcpy(gsymtab + j * blocksize,
2069 addr + filelist[gsym_record].extent_list[j] * blocksize,
2070 blocksize);
2074 * This record also contains information about where in the
2075 * remaining records we will be able to find the start of the
2076 * line number table. We could locate that bit using heuristics,
2077 * but since we have the info handy, we might as well use it.
2079 offset = sizeof(*hd);
2080 while(1==1)
2082 fent = (struct file_ent *) (buffer + offset);
2083 if( offset > hd->ftab_len )
2085 break;
2088 if( fent->file_number == 0 || fent->file_number >= npair )
2090 break;
2093 filelist[fent->file_number].linetab_offset =
2094 fent->linetab_offset;
2095 filelist[fent->file_number].linetab_len =
2096 fent->linetab_len;
2098 * Figure out the offset of the next entry.
2099 * There is a fixed part of the record and a variable
2100 * length filename which we must also skip past.
2102 offset += ((unsigned int) &fent->filename - (unsigned int) fent)
2103 + strlen(fent->filename) + 1;
2104 offset += strlen(buffer+offset) + 1;
2105 offset = (offset + 3) & ~3;
2111 * Two different magic numbers used as dates.
2112 * These indicate the 'type' table.
2114 if( *pnt == 19950410
2115 || *pnt == 19951122 )
2117 DEBUG_ParseTypeTable(buffer, filelist[i].record_len);
2118 continue;
2122 * This is something we really want to look at, since it contains
2123 * real debug info. Anything that doesn't match this can be
2124 * ignored for now.
2126 if( *pnt == 1 )
2129 * First, snag the line table, if we have one. This always
2130 * occurs at the end of the record, so we take the linetab
2131 * offset as the end of the normal part of the record.
2133 linetab = NULL;
2134 if( filelist[i].linetab_len != 0 )
2136 linetab = DEBUG_SnarfLinetab(buffer + filelist[i].linetab_offset,
2137 filelist[i].linetab_len);
2138 DEBUG_SnarfCodeView(deefer, buffer,
2139 filelist[i].linetab_offset,
2140 linetab);
2142 else
2144 DEBUG_SnarfCodeView(deefer, buffer,
2145 filelist[i].record_len,
2146 linetab);
2148 continue;
2153 * Finally, process the global symbol table itself. There isn't
2154 * a line number component to this, so we just toss everything
2155 * into the mix and it all should work out.
2157 if( gsym_record != 0 )
2159 DEBUG_SnarfCodeView(deefer, gsymtab - sizeof(int),
2160 filelist[gsym_record].record_len,
2161 NULL);
2164 leave:
2166 if( gsymtab != NULL )
2168 DBG_free(gsymtab);
2169 gsymtab = NULL;
2172 if( buffer != NULL )
2174 DBG_free(buffer);
2177 if( filelist != NULL )
2179 DBG_free(filelist);
2182 if( addr != (char *) 0xffffffff )
2184 munmap(addr, statbuf.st_size);
2187 if( fd != -1 )
2189 close(fd);
2192 return TRUE;
2196 * Process DBG file which contains debug information.
2198 /* static */
2200 DEBUG_ProcessDBGFile(struct deferred_debug_info * deefer, char * filename)
2202 char * addr = (char *) 0xffffffff;
2203 char * codeview;
2204 struct CV4_DirHead * codeview_dir;
2205 struct CV4_DirEnt * codeview_dent;
2206 PIMAGE_DEBUG_DIRECTORY dbghdr;
2207 struct deferred_debug_info deefer2;
2208 int fd = -1;
2209 int i;
2210 int j;
2211 struct codeview_linetab_hdr * linetab;
2212 int nsect;
2213 PIMAGE_SEPARATE_DEBUG_HEADER pdbg = NULL;
2214 IMAGE_SECTION_HEADER * sectp;
2215 struct stat statbuf;
2216 int status;
2217 char dbg_file[MAX_PATHNAME_LEN];
2219 LocateDebugInfoFile(filename, dbg_file);
2220 status = stat(dbg_file, &statbuf);
2221 if( status == -1 )
2223 fprintf(stderr, "-Unable to open .DBG file %s\n", dbg_file);
2224 goto leave;
2228 * Now open the file, so that we can mmap() it.
2230 fd = open(dbg_file, O_RDONLY);
2231 if( fd == -1 )
2233 fprintf(stderr, "Unable to open .DBG file %s\n", dbg_file);
2234 goto leave;
2239 * Now mmap() the file.
2241 addr = mmap(0, statbuf.st_size, PROT_READ,
2242 MAP_PRIVATE, fd, 0);
2243 if( addr == (char *) 0xffffffff )
2245 fprintf(stderr, "Unable to mmap .DBG file %s\n", dbg_file);
2246 goto leave;
2249 pdbg = (PIMAGE_SEPARATE_DEBUG_HEADER) addr;
2251 if( pdbg->TimeDateStamp != deefer->dbgdir->TimeDateStamp )
2253 fprintf(stderr, "Warning - %s has incorrect internal timestamp\n",
2254 dbg_file);
2255 /* goto leave; */
2257 Well, sometimes this happens to DBG files which ARE REALLY the right .DBG
2258 files but nonetheless this check fails. Anyway, WINDBG (debugger for
2259 Windows by Microsoft) loads debug symbols which have incorrect timestamps.
2263 fprintf(stderr, "Processing symbols from %s...\n", dbg_file);
2265 dbghdr = (PIMAGE_DEBUG_DIRECTORY) ( addr + sizeof(*pdbg)
2266 + pdbg->NumberOfSections * sizeof(IMAGE_SECTION_HEADER)
2267 + pdbg->ExportedNamesSize);
2269 sectp = (PIMAGE_SECTION_HEADER) ((char *) pdbg + sizeof(*pdbg));
2270 nsect = pdbg->NumberOfSections;
2272 for( i=0; i < pdbg->DebugDirectorySize / sizeof(*pdbg); i++, dbghdr++ )
2274 switch(dbghdr->Type)
2276 case IMAGE_DEBUG_TYPE_COFF:
2278 * Dummy up a deferred debug header to handle the
2279 * COFF stuff embedded within the DBG file.
2281 memset((char *) &deefer2, 0, sizeof(deefer2));
2282 deefer2.dbg_info = (addr + dbghdr->PointerToRawData);
2283 deefer2.dbg_size = dbghdr->SizeOfData;
2284 deefer2.load_addr = deefer->load_addr;
2286 DEBUG_ProcessCoff(&deefer2);
2287 break;
2288 case IMAGE_DEBUG_TYPE_CODEVIEW:
2290 * This is the older format by which codeview stuff is
2291 * stored, known as the 'NB09' format. Newer executables
2292 * and dlls created by VC++ use PDB files instead, which
2293 * have lots of internal similarities, but the overall
2294 * format and structure is quite different.
2296 codeview = (addr + dbghdr->PointerToRawData);
2299 * The first thing in the codeview section should be
2300 * an 'NB09' identifier. As a sanity check, make sure
2301 * it is there.
2303 if( *((unsigned int*) codeview) != 0x3930424e )
2305 break;
2309 * Next we need to find the directory. This is easy too.
2311 codeview_dir = (struct CV4_DirHead *)
2312 (codeview + ((unsigned int*) codeview)[1]);
2315 * Some more sanity checks. Make sure that everything
2316 * is as we expect it.
2318 if( codeview_dir->next_offset != 0
2319 || codeview_dir->dhsize != sizeof(*codeview_dir)
2320 || codeview_dir->desize != sizeof(*codeview_dent) )
2322 break;
2324 codeview_dent = (struct CV4_DirEnt *) (codeview_dir + 1);
2326 for(j=0; j < codeview_dir->ndir; j++, codeview_dent++)
2328 if( codeview_dent->subsect_number == sstAlignSym )
2331 * Check the previous entry. If it is a
2332 * sstSrcModule, it contains the line number
2333 * info for this file.
2335 linetab = NULL;
2336 if( codeview_dent[1].module_number == codeview_dent[0].module_number
2337 && codeview_dent[1].subsect_number == sstSrcModule )
2339 linetab = DEBUG_SnarfLinetab(
2340 codeview + codeview_dent[1].offset,
2341 codeview_dent[1].size);
2344 if( codeview_dent[-1].module_number == codeview_dent[0].module_number
2345 && codeview_dent[-1].subsect_number == sstSrcModule )
2347 linetab = DEBUG_SnarfLinetab(
2348 codeview + codeview_dent[-1].offset,
2349 codeview_dent[-1].size);
2352 * Now process the CV stuff.
2354 DEBUG_SnarfCodeView(deefer,
2355 codeview + codeview_dent->offset,
2356 codeview_dent->size,
2357 linetab);
2361 break;
2362 default:
2363 break;
2366 leave:
2368 if( addr != (char *) 0xffffffff )
2370 munmap(addr, statbuf.st_size);
2373 if( fd != -1 )
2375 close(fd);
2378 return TRUE;
2382 DEBUG_ProcessDeferredDebug()
2384 struct deferred_debug_info * deefer;
2385 struct CodeViewDebug * cvd;
2386 struct MiscDebug * misc;
2387 char * filename;
2388 int last_proc = -1;
2389 int need_print =0;
2391 DEBUG_InitCVDataTypes();
2393 for(deefer = dbglist; deefer; deefer = deefer->next)
2395 if( deefer->loaded )
2397 continue;
2400 if( last_proc != deefer->dbg_index )
2402 if (!need_print)
2404 fprintf(stderr, "DeferredDebug for:");
2405 need_print=1;
2407 fprintf(stderr, " %s",deefer->module_name);
2408 last_proc = deefer->dbg_index;
2411 switch(deefer->dbgdir->Type)
2413 case IMAGE_DEBUG_TYPE_COFF:
2415 * Standard COFF debug information that VC++ adds when you
2416 * use /debugtype:both with the linker.
2418 #if 0
2419 fprintf(stderr, "Processing COFF symbols...\n");
2420 #endif
2421 DEBUG_ProcessCoff(deefer);
2422 break;
2423 case IMAGE_DEBUG_TYPE_CODEVIEW:
2425 * This is a pointer to a PDB file of some sort.
2427 cvd = (struct CodeViewDebug *) deefer->dbg_info;
2429 if( strcmp(cvd->cv_nbtype, "NB10") != 0 )
2432 * Whatever this is, we don't know how to deal with
2433 * it yet.
2435 break;
2437 DEBUG_ProcessPDBFile(deefer, cvd->cv_name);
2438 #if 0
2439 fprintf(stderr, "Processing PDB file %s\n", cvd->cv_name);
2440 #endif
2441 break;
2442 case IMAGE_DEBUG_TYPE_MISC:
2444 * A pointer to a .DBG file of some sort. These files
2445 * can contain either CV4 or COFF information. Open
2446 * the file, and try to do the right thing with it.
2448 misc = (struct MiscDebug *) deefer->dbg_info;
2450 filename = strrchr((char *) &misc->Data, '.');
2453 * Ignore the file if it doesn't have a .DBG extension.
2455 if( (filename == NULL)
2456 || ( (strcmp(filename, ".dbg") != 0)
2457 && (strcmp(filename, ".DBG") != 0)) )
2459 break;
2462 filename = (char *) &misc->Data;
2465 * Do the dirty deed...
2467 DEBUG_ProcessDBGFile(deefer, filename);
2469 break;
2470 default:
2472 * We should never get here...
2474 break;
2477 if(need_print)
2478 fprintf(stderr, "\n");
2479 return TRUE;
2483 /***********************************************************************
2484 * DEBUG_InfoShare
2486 * Display shared libarary information.
2488 void DEBUG_InfoShare(void)
2490 struct deferred_debug_info * deefer;
2492 fprintf(stderr,"Address\t\tModule\tName\n");
2494 for(deefer = dbglist; deefer; deefer = deefer->next)
2496 fprintf(stderr,"0x%8.8x\t(%s)\t%s\n", (unsigned int) deefer->load_addr,
2497 deefer->module ? "Win32" : "ELF", deefer->module_name);