2 * File hash.c - generate hash tables for Wine debugger symbols
4 * Copyright (C) 1993, Eric Youngdale.
13 #include <sys/types.h>
20 #define NR_NAME_HASH 16384
22 #define PATH_MAX _MAX_PATH
26 static char * reg_name
[] =
28 "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi"
31 static unsigned reg_ofs
[] =
33 FIELD_OFFSET(CONTEXT
, Eax
), FIELD_OFFSET(CONTEXT
, Ecx
),
34 FIELD_OFFSET(CONTEXT
, Edx
), FIELD_OFFSET(CONTEXT
, Ebx
),
35 FIELD_OFFSET(CONTEXT
, Esp
), FIELD_OFFSET(CONTEXT
, Ebp
),
36 FIELD_OFFSET(CONTEXT
, Esi
), FIELD_OFFSET(CONTEXT
, Edi
)
39 static char * reg_name
[] = { NULL
}; /* FIXME */
40 static unsigned reg_ofs
[] = { 0 };
46 struct name_hash
* next
; /* Used to look up within name hash */
52 WineLocals
* local_vars
;
60 unsigned short breakpoint_offset
;
61 unsigned int symbol_size
;
65 static BOOL
DEBUG_GetStackSymbolValue( const char * name
, DBG_VALUE
*value
);
66 static int sortlist_valid
= FALSE
;
68 static int sorttab_nsym
;
69 static struct name_hash
** addr_sorttab
= NULL
;
71 static struct name_hash
* name_hash_table
[NR_NAME_HASH
];
73 static unsigned int name_hash( const char * name
)
75 unsigned int hash
= 0;
83 hash
= (hash
<< 4) + *p
++;
85 if( (tmp
= (hash
& 0xf0000000)) )
91 return hash
% NR_NAME_HASH
;
95 DEBUG_cmp_sym(const void * p1
, const void * p2
)
97 struct name_hash
** name1
= (struct name_hash
**) p1
;
98 struct name_hash
** name2
= (struct name_hash
**) p2
;
100 if( ((*name1
)->flags
& SYM_INVALID
) != 0 )
105 if( ((*name2
)->flags
& SYM_INVALID
) != 0 )
110 if( (*name1
)->value
.addr
.seg
> (*name2
)->value
.addr
.seg
)
115 if( (*name1
)->value
.addr
.seg
< (*name2
)->value
.addr
.seg
)
120 if( (*name1
)->value
.addr
.off
> (*name2
)->value
.addr
.off
)
125 if( (*name1
)->value
.addr
.off
< (*name2
)->value
.addr
.off
)
133 /***********************************************************************
134 * DEBUG_ResortSymbols
136 * Rebuild sorted list of symbols.
140 DEBUG_ResortSymbols(void)
142 struct name_hash
*nh
;
146 for(i
=0; i
<NR_NAME_HASH
; i
++)
148 for (nh
= name_hash_table
[i
]; nh
; nh
= nh
->next
)
150 if( (nh
->flags
& SYM_INVALID
) == 0 )
153 fprintf( stderr
, "Symbol %s is invalid\n", nh
->name
);
163 addr_sorttab
= (struct name_hash
**) DBG_realloc(addr_sorttab
,
164 nsym
* sizeof(struct name_hash
*));
167 for(i
=0; i
<NR_NAME_HASH
; i
++)
169 for (nh
= name_hash_table
[i
]; nh
; nh
= nh
->next
)
171 if( (nh
->flags
& SYM_INVALID
) == 0 )
172 addr_sorttab
[nsym
++] = nh
;
176 qsort(addr_sorttab
, nsym
,
177 sizeof(struct name_hash
*), DEBUG_cmp_sym
);
178 sortlist_valid
= TRUE
;
182 /***********************************************************************
185 * Add a symbol to the table.
188 DEBUG_AddSymbol( const char * name
, const DBG_VALUE
*value
, const char * source
,
191 struct name_hash
* new;
192 struct name_hash
*nh
;
193 static char prev_source
[PATH_MAX
] = {'\0', };
194 static char * prev_duped_source
= NULL
;
198 assert(value
->cookie
== DV_TARGET
|| value
->cookie
== DV_HOST
);
200 hash
= name_hash(name
);
201 for (nh
= name_hash_table
[hash
]; nh
; nh
= nh
->next
)
203 if( ((nh
->flags
& SYM_INVALID
) != 0) && strcmp(name
, nh
->name
) == 0 )
205 nh
->value
.addr
= value
->addr
;
207 if( nh
->value
.type
== NULL
&& value
->type
!= NULL
)
209 nh
->value
.type
= value
->type
;
210 nh
->value
.cookie
= value
->cookie
;
212 /* it may happen that the same symbol is defined in several compilation
213 * units, but the linker decides to merge it into a single instance.
214 * in that case, we don't clear the invalid flag for all the compilation
215 * units (N_GSYM), and wait to get the symbol from the symtab
217 if ((flags
& SYM_INVALID
) == 0)
218 nh
->flags
&= ~SYM_INVALID
;
222 if (nh
->value
.addr
.seg
== value
->addr
.seg
&&
223 nh
->value
.addr
.off
== value
->addr
.off
&&
224 strcmp(name
, nh
->name
) == 0 )
231 * First see if we already have an entry for this symbol. If so
232 * return it, so we don't end up with duplicates.
235 new = (struct name_hash
*) DBG_alloc(sizeof(struct name_hash
));
237 new->name
= DBG_strdup(name
);
242 * This is an enhancement to reduce memory consumption. The idea
243 * is that we duplicate a given string only once. This is a big
244 * win if there are lots of symbols defined in a given source file.
246 if( strcmp(source
, prev_source
) == 0 )
248 new->sourcefile
= prev_duped_source
;
252 strcpy(prev_source
, source
);
253 prev_duped_source
= new->sourcefile
= DBG_strdup(source
);
258 new->sourcefile
= NULL
;
262 new->lines_alloc
= 0;
266 new->locals_alloc
= 0;
267 new->local_vars
= NULL
;
272 /* Now insert into the hash table */
273 new->next
= name_hash_table
[hash
];
274 name_hash_table
[hash
] = new;
277 * Check some heuristics based upon the file name to see whether
278 * we want to step through this guy or not. These are machine generated
279 * assembly files that are used to translate between the MS way of
280 * calling things and the GCC way of calling things. In general we
281 * always want to step through.
285 c
= strrchr(source
, '.');
286 if( c
!= NULL
&& strcmp(c
, ".s") == 0 )
288 c
= strrchr(source
, '/');
292 if( (strcmp(c
, "callfrom16.s") == 0)
293 || (strcmp(c
, "callto16.s") == 0)
294 || (strcmp(c
, "call32.s") == 0) )
296 new->flags
|= SYM_TRAMPOLINE
;
302 sortlist_valid
= FALSE
;
306 BOOL
DEBUG_Normalize(struct name_hash
* nh
)
310 * We aren't adding any more locals or linenumbers to this function.
311 * Free any spare memory that we might have allocated.
318 if( nh
->n_locals
!= nh
->locals_alloc
)
320 nh
->locals_alloc
= nh
->n_locals
;
321 nh
->local_vars
= DBG_realloc(nh
->local_vars
,
322 nh
->locals_alloc
* sizeof(WineLocals
));
325 if( nh
->n_lines
!= nh
->lines_alloc
)
327 nh
->lines_alloc
= nh
->n_lines
;
328 nh
->linetab
= DBG_realloc(nh
->linetab
,
329 nh
->lines_alloc
* sizeof(WineLineNo
));
335 /***********************************************************************
336 * DEBUG_GetSymbolValue
338 * Get the address of a named symbol.
340 BOOL
DEBUG_GetSymbolValue( const char * name
, const int lineno
,
341 DBG_VALUE
*value
, int bp_flag
)
344 struct name_hash
*nh
;
346 for(nh
= name_hash_table
[name_hash(name
)]; nh
; nh
= nh
->next
)
348 if( (nh
->flags
& SYM_INVALID
) != 0 )
353 if (!strcmp(nh
->name
, name
)) break;
356 if (!nh
&& (name
[0] != '_'))
359 strcpy(buffer
+1, name
);
360 for(nh
= name_hash_table
[name_hash(buffer
)]; nh
; nh
= nh
->next
)
362 if( (nh
->flags
& SYM_INVALID
) != 0 )
366 if (!strcmp(nh
->name
, buffer
)) break;
371 * If we don't have anything here, then try and see if this
372 * is a local symbol to the current stack frame. No matter
373 * what, we have nothing more to do, so we let that function
374 * decide what we ultimately return.
378 return DEBUG_GetStackSymbolValue(name
, value
);
381 value
->type
= nh
->value
.type
;
382 value
->cookie
= nh
->value
.cookie
;
383 return DEBUG_GetLineNumberAddr( nh
, lineno
, &value
->addr
, bp_flag
);
386 /***********************************************************************
387 * DEBUG_GetLineNumberAddr
389 * Get the address of a named symbol.
391 BOOL
DEBUG_GetLineNumberAddr( struct name_hash
* nh
, const int lineno
,
392 DBG_ADDR
*addr
, int bp_flag
)
398 *addr
= nh
->value
.addr
;
401 addr
->off
+= nh
->breakpoint_offset
;
407 * Search for the specific line number. If we don't find it,
410 if( nh
->linetab
== NULL
)
415 for(i
=0; i
< nh
->n_lines
; i
++ )
417 if( nh
->linetab
[i
].line_number
== lineno
)
419 *addr
= nh
->linetab
[i
].pc_offset
;
425 * This specific line number not found.
434 /***********************************************************************
435 * DEBUG_SetSymbolValue
437 * Set the address of a named symbol.
439 BOOL
DEBUG_SetSymbolValue( const char * name
, const DBG_VALUE
*value
)
442 struct name_hash
*nh
;
444 assert(value
->cookie
== DV_TARGET
|| value
->cookie
== DV_HOST
);
446 for(nh
= name_hash_table
[name_hash(name
)]; nh
; nh
= nh
->next
)
447 if (!strcmp(nh
->name
, name
)) break;
449 if (!nh
&& (name
[0] != '_'))
452 strcpy(buffer
+1, name
);
453 for(nh
= name_hash_table
[name_hash(buffer
)]; nh
; nh
= nh
->next
)
454 if (!strcmp(nh
->name
, buffer
)) break;
457 if (!nh
) return FALSE
;
459 nh
->flags
&= ~SYM_INVALID
;
460 DEBUG_FixAddress( &nh
->value
.addr
, DEBUG_context
.SegDs
);
465 /***********************************************************************
466 * DEBUG_FindNearestSymbol
468 * Find the symbol nearest to a given address.
469 * If ebp is specified as non-zero, it means we should dump the argument
470 * list into the string we return as well.
472 const char * DEBUG_FindNearestSymbol( const DBG_ADDR
*addr
, int flag
,
473 struct name_hash
** rtn
,
475 struct list_id
* source
)
477 static char name_buffer
[MAX_PATH
+ 256];
478 static char arglist
[1024];
479 static char argtmp
[256];
480 struct name_hash
* nearest
= NULL
;
484 char * lineinfo
, *sourcefile
;
496 source
->sourcefile
= NULL
;
500 if( sortlist_valid
== FALSE
)
502 DEBUG_ResortSymbols();
505 if( sortlist_valid
== FALSE
)
511 * FIXME - use the binary search that we added to
512 * the function DEBUG_CheckLinenoStatus. Better yet, we should
513 * probably keep some notion of the current function so we don't
514 * have to search every time.
517 * Binary search to find closest symbol.
521 if( addr_sorttab
[0]->value
.addr
.seg
> addr
->seg
522 || ( addr_sorttab
[0]->value
.addr
.seg
== addr
->seg
523 && addr_sorttab
[0]->value
.addr
.off
> addr
->off
) )
527 else if( addr_sorttab
[high
- 1]->value
.addr
.seg
< addr
->seg
528 || ( addr_sorttab
[high
- 1]->value
.addr
.seg
== addr
->seg
529 && addr_sorttab
[high
- 1]->value
.addr
.off
< addr
->off
) )
531 nearest
= addr_sorttab
[high
- 1];
537 mid
= (high
+ low
)/2;
541 * See if there are any other entries that might also
542 * have the same address, and would also have a line
545 if( mid
> 0 && addr_sorttab
[mid
]->linetab
== NULL
)
547 if( (addr_sorttab
[mid
- 1]->value
.addr
.seg
==
548 addr_sorttab
[mid
]->value
.addr
.seg
)
549 && (addr_sorttab
[mid
- 1]->value
.addr
.off
==
550 addr_sorttab
[mid
]->value
.addr
.off
)
551 && (addr_sorttab
[mid
- 1]->linetab
!= NULL
) )
557 if( (mid
< sorttab_nsym
- 1)
558 && (addr_sorttab
[mid
]->linetab
== NULL
) )
560 if( (addr_sorttab
[mid
+ 1]->value
.addr
.seg
==
561 addr_sorttab
[mid
]->value
.addr
.seg
)
562 && (addr_sorttab
[mid
+ 1]->value
.addr
.off
==
563 addr_sorttab
[mid
]->value
.addr
.off
)
564 && (addr_sorttab
[mid
+ 1]->linetab
!= NULL
) )
569 nearest
= addr_sorttab
[mid
];
571 fprintf(stderr
, "Found %x:%x when looking for %x:%x %x %s\n",
572 addr_sorttab
[mid
]->value
.addr
.seg
,
573 addr_sorttab
[mid
]->value
.addr
.off
,
574 addr
->seg
, addr
->off
,
575 addr_sorttab
[mid
]->linetab
,
576 addr_sorttab
[mid
]->name
);
580 if( (addr_sorttab
[mid
]->value
.addr
.seg
< addr
->seg
)
581 || ( addr_sorttab
[mid
]->value
.addr
.seg
== addr
->seg
582 && addr_sorttab
[mid
]->value
.addr
.off
<= addr
->off
) )
593 if (!nearest
) return NULL
;
601 * Fill in the relevant bits to the structure so that we can
602 * locate the source and line for this bit of code.
606 source
->sourcefile
= nearest
->sourcefile
;
607 if( nearest
->linetab
== NULL
)
613 source
->line
= nearest
->linetab
[0].line_number
;
621 * Prepare to display the argument list. If ebp is specified, it is
622 * the framepointer for the function in question. If not specified,
623 * we don't want the arglist.
625 memset(arglist
, '\0', sizeof(arglist
));
628 for(i
=0; i
< nearest
->n_locals
; i
++ )
631 * If this is a register (offset == 0) or a local
632 * variable, we don't want to know about it.
634 if( nearest
->local_vars
[i
].offset
<= 0 )
639 ptr
= (unsigned int *) (ebp
+ nearest
->local_vars
[i
].offset
);
640 if( arglist
[0] == '\0' )
646 strcat(arglist
, ", ");
648 DEBUG_READ_MEM_VERBOSE(ptr
, &val
, sizeof(val
));
649 sprintf(argtmp
, "%s=0x%x", nearest
->local_vars
[i
].name
, val
);
651 strcat(arglist
, argtmp
);
653 if( arglist
[0] == '(' )
655 strcat(arglist
, ")");
659 if( (nearest
->sourcefile
!= NULL
) && (flag
== TRUE
)
660 && (addr
->off
- nearest
->value
.addr
.off
< 0x100000) )
664 * Try and find the nearest line number to the current offset.
666 if( nearest
->linetab
!= NULL
)
669 high
= nearest
->n_lines
;
670 while ((high
- low
) > 1)
672 mid
= (high
+ low
) / 2;
673 if (addr
->off
< nearest
->linetab
[mid
].pc_offset
.off
)
678 lineno
= nearest
->linetab
[low
].line_number
;
683 sprintf(linebuff
, ":%d", lineno
);
687 source
->line
= lineno
;
691 /* Remove the path from the file name */
692 sourcefile
= strrchr( nearest
->sourcefile
, '/' );
693 if (!sourcefile
) sourcefile
= nearest
->sourcefile
;
696 if (addr
->off
== nearest
->value
.addr
.off
)
697 sprintf( name_buffer
, "%s%s [%s%s]", nearest
->name
,
698 arglist
, sourcefile
, lineinfo
);
700 sprintf( name_buffer
, "%s+0x%lx%s [%s%s]", nearest
->name
,
701 addr
->off
- nearest
->value
.addr
.off
,
702 arglist
, sourcefile
, lineinfo
);
706 if (addr
->off
== nearest
->value
.addr
.off
)
707 sprintf( name_buffer
, "%s%s", nearest
->name
, arglist
);
709 if (addr
->seg
&& (nearest
->value
.addr
.seg
!=addr
->seg
))
712 sprintf( name_buffer
, "%s+0x%lx%s", nearest
->name
,
713 addr
->off
- nearest
->value
.addr
.off
, arglist
);
720 /***********************************************************************
721 * DEBUG_ReadSymbolTable
723 * Read a symbol file into the hash table.
725 void DEBUG_ReadSymbolTable( const char * filename
)
735 if (!(symbolfile
= fopen(filename
, "r")))
737 fprintf( stderr
, "Unable to open symbol table %s\n", filename
);
741 fprintf( stderr
, "Reading symbols from file %s\n", filename
);
746 value
.cookie
= DV_TARGET
;
750 fgets( buffer
, sizeof(buffer
), symbolfile
);
751 if (feof(symbolfile
)) break;
753 /* Strip any text after a # sign (i.e. comments) */
756 if(*cpnt
++ == '#') { *cpnt
= 0; break; }
758 /* Quietly ignore any lines that have just whitespace */
762 if(*cpnt
!= ' ' && *cpnt
!= '\t') break;
765 if (!(*cpnt
) || *cpnt
== '\n') continue;
767 nargs
= sscanf(buffer
, "%lx %c %s", &value
.addr
.off
, &type
, name
);
768 DEBUG_AddSymbol( name
, &value
, NULL
, SYM_WINE
);
774 /***********************************************************************
775 * DEBUG_LoadEntryPoints16
777 * Load the entry points of a Win16 module into the hash table.
779 static void DEBUG_LoadEntryPoints16( HMODULE16 hModule
, NE_MODULE
*pModule
,
785 unsigned char *cpnt
= (unsigned char *)pModule
+ pModule
->name_table
;
788 value
.cookie
= DV_TARGET
;
792 /* First search the resident names */
796 cpnt
+= *cpnt
+ 1 + sizeof(WORD
);
797 sprintf( buffer
, "%s.%.*s", name
, *cpnt
, cpnt
+ 1 );
798 if ((address
= NE_GetEntryPoint(hModule
, *(WORD
*)(cpnt
+ *cpnt
+ 1))))
800 value
.addr
.seg
= HIWORD(address
);
801 value
.addr
.off
= LOWORD(address
);
802 DEBUG_AddSymbol( buffer
, &value
, NULL
, SYM_WIN32
| SYM_FUNC
);
806 /* Now search the non-resident names table */
808 if (!pModule
->nrname_handle
) return; /* No non-resident table */
809 cpnt
= (char *)GlobalLock16( pModule
->nrname_handle
);
812 cpnt
+= *cpnt
+ 1 + sizeof(WORD
);
813 sprintf( buffer
, "%s.%.*s", name
, *cpnt
, cpnt
+ 1 );
814 if ((address
= NE_GetEntryPoint(hModule
, *(WORD
*)(cpnt
+ *cpnt
+ 1))))
816 value
.addr
.seg
= HIWORD(address
);
817 value
.addr
.off
= LOWORD(address
);
818 DEBUG_AddSymbol( buffer
, &value
, NULL
, SYM_WIN32
| SYM_FUNC
);
824 /***********************************************************************
825 * DEBUG_LoadEntryPoints32
827 * Load the entry points of a Win32 module into the hash table.
829 static void DEBUG_LoadEntryPoints32( HMODULE hModule
, const char *name
)
831 #define RVA(x) (hModule+(DWORD)(x))
836 IMAGE_SECTION_HEADER
*pe_seg
;
837 IMAGE_EXPORT_DIRECTORY
*exports
;
838 IMAGE_DATA_DIRECTORY
*dir
;
844 value
.cookie
= DV_TARGET
;
848 /* Add start of DLL */
850 value
.addr
.off
= hModule
;
851 DEBUG_AddSymbol( name
, &value
, NULL
, SYM_WIN32
| SYM_FUNC
);
853 /* Add entry point */
855 sprintf( buffer
, "%s.EntryPoint", name
);
856 value
.addr
.off
= (DWORD
)RVA_PTR( hModule
, OptionalHeader
.AddressOfEntryPoint
);
857 DEBUG_AddSymbol( buffer
, &value
, NULL
, SYM_WIN32
| SYM_FUNC
);
859 /* Add start of sections */
861 pe_seg
= PE_SECTIONS(hModule
);
862 for (i
= 0; i
< PE_HEADER(hModule
)->FileHeader
.NumberOfSections
; i
++)
864 sprintf( buffer
, "%s.%s", name
, pe_seg
->Name
);
865 value
.addr
.off
= RVA(pe_seg
->VirtualAddress
);
866 DEBUG_AddSymbol( buffer
, &value
, NULL
, SYM_WIN32
| SYM_FUNC
);
870 /* Add exported functions */
872 dir
= &PE_HEADER(hModule
)->OptionalHeader
.
873 DataDirectory
[IMAGE_DIRECTORY_ENTRY_EXPORT
];
876 exports
= (IMAGE_EXPORT_DIRECTORY
*)RVA( dir
->VirtualAddress
);
877 ordinals
= (WORD
*)RVA( exports
->AddressOfNameOrdinals
);
878 names
= (const char **)RVA( exports
->AddressOfNames
);
879 functions
= (void **)RVA( exports
->AddressOfFunctions
);
881 for (i
= 0; i
< exports
->NumberOfNames
; i
++)
883 if (!names
[i
]) continue;
884 sprintf( buffer
, "%s.%s", name
, (char *)RVA(names
[i
]) );
885 value
.addr
.off
= RVA( functions
[ordinals
[i
]] );
886 DEBUG_AddSymbol( buffer
, &value
, NULL
, SYM_WIN32
| SYM_FUNC
);
889 for (i
= 0; i
< exports
->NumberOfFunctions
; i
++)
891 if (!functions
[i
]) continue;
892 /* Check if we already added it with a name */
893 for (j
= 0; j
< exports
->NumberOfNames
; j
++)
894 if ((ordinals
[j
] == i
) && names
[j
]) break;
895 if (j
< exports
->NumberOfNames
) continue;
896 sprintf( buffer
, "%s.%ld", name
, i
+ exports
->Base
);
897 value
.addr
.off
= (DWORD
)RVA( functions
[i
] );
898 DEBUG_AddSymbol( buffer
, &value
, NULL
, SYM_WIN32
| SYM_FUNC
);
901 DEBUG_RegisterDebugInfo(hModule
, name
);
905 typedef struct tag_lmr
{
908 struct tag_lmr
* next
;
909 } DBG_LoadedModuleRef
;
917 static BOOL
DEBUG_LEPHelper(const char* mod_name
, BOOL is16
, DBG_LEPData
* lep
)
919 static DBG_LoadedModuleRef
* lmr
= NULL
;
920 DBG_LoadedModuleRef
* p
;
921 DBG_LoadedModuleRef
** pp1
;
922 DBG_LoadedModuleRef
* p2
;
923 int len
= strlen(mod_name
);
926 for (p
= lmr
; p
; p
= p
->next
) {
927 cmp
= strcasecmp(p
->module_name
, mod_name
);
928 if (cmp
== 0 && p
->is16
== is16
)
935 if (lep
->pfx
) fprintf( stderr
, lep
->pfx
);
936 fprintf( stderr
, " " );
941 if ((lep
->rowcount
+ len
) > 76)
943 fprintf( stderr
, "\n ");
946 fprintf( stderr
, " %s", mod_name
);
947 lep
->rowcount
+= len
+ 1;
949 p
= DBG_alloc(sizeof(*lmr
));
950 p
->module_name
= DBG_strdup(mod_name
);
954 for (pp1
= &lmr
; *pp1
; pp1
= &(*pp1
)->next
) {
955 if (strcasecmp((*pp1
)->module_name
, mod_name
) > 0)
964 else if (*pp1
== NULL
)
978 /***********************************************************************
979 * DEBUG_LoadEntryPoints
981 * Load the entry points of all the modules into the hash table.
983 int DEBUG_LoadEntryPoints(const char* pfx
)
990 PDB
* current
= PROCESS_Current();
995 /* FIXME: we assume that a module is never removed from memory */
997 for (ok
= ModuleFirst16(&entry
); ok
; ok
= ModuleNext16(&entry
))
999 if (!(pModule
= NE_GetPtr( entry
.hModule
))) continue;
1000 if (!(pModule
->flags
& NE_FFLAGS_WIN32
) && /* NE module */
1001 DEBUG_LEPHelper( entry
.szModule
, TRUE
, &lep
))
1002 DEBUG_LoadEntryPoints16( entry
.hModule
, pModule
, entry
.szModule
);
1005 for (wm
= current
->modref_list
; wm
; wm
=wm
->next
)
1007 if ((wm
->flags
& WINE_MODREF_INTERNAL
))
1009 if (DEBUG_LEPHelper( wm
->modname
, FALSE
, &lep
))
1010 DEBUG_LoadEntryPoints32( wm
->module
, wm
->modname
);
1013 if (lep
.first
) fprintf( stderr
, " $");
1014 for (wm
= current
->modref_list
; wm
; wm
=wm
->next
)
1016 if (!(wm
->flags
& WINE_MODREF_INTERNAL
))
1018 if (DEBUG_LEPHelper( wm
->modname
, FALSE
, &lep
))
1019 DEBUG_LoadEntryPoints32( wm
->module
, wm
->modname
);
1022 if (lep
.first
) fprintf( stderr
, "\n" );
1028 DEBUG_AddLineNumber( struct name_hash
* func
, int line_num
,
1029 unsigned long offset
)
1036 if( func
->n_lines
+ 1 >= func
->lines_alloc
)
1038 func
->lines_alloc
+= 64;
1039 func
->linetab
= DBG_realloc(func
->linetab
,
1040 func
->lines_alloc
* sizeof(WineLineNo
));
1043 func
->linetab
[func
->n_lines
].line_number
= line_num
;
1044 func
->linetab
[func
->n_lines
].pc_offset
.seg
= func
->value
.addr
.seg
;
1045 func
->linetab
[func
->n_lines
].pc_offset
.off
= func
->value
.addr
.off
+ offset
;
1050 struct wine_locals
*
1051 DEBUG_AddLocal( struct name_hash
* func
, int regno
,
1062 if( func
->n_locals
+ 1 >= func
->locals_alloc
)
1064 func
->locals_alloc
+= 32;
1065 func
->local_vars
= DBG_realloc(func
->local_vars
,
1066 func
->locals_alloc
* sizeof(WineLocals
));
1069 func
->local_vars
[func
->n_locals
].regno
= regno
;
1070 func
->local_vars
[func
->n_locals
].offset
= offset
;
1071 func
->local_vars
[func
->n_locals
].pc_start
= pc_start
;
1072 func
->local_vars
[func
->n_locals
].pc_end
= pc_end
;
1073 func
->local_vars
[func
->n_locals
].name
= DBG_strdup(name
);
1074 func
->local_vars
[func
->n_locals
].type
= NULL
;
1077 return &func
->local_vars
[func
->n_locals
- 1];
1081 DEBUG_DumpHashInfo(void)
1085 struct name_hash
*nh
;
1088 * Utility function to dump stats about the hash table.
1090 for(i
=0; i
<NR_NAME_HASH
; i
++)
1093 for (nh
= name_hash_table
[i
]; nh
; nh
= nh
->next
)
1097 fprintf(stderr
, "Bucket %d: %d\n", i
, depth
);
1101 /***********************************************************************
1102 * DEBUG_CheckLinenoStatus
1104 * Find the symbol nearest to a given address.
1105 * If ebp is specified as non-zero, it means we should dump the argument
1106 * list into the string we return as well.
1108 int DEBUG_CheckLinenoStatus( const DBG_ADDR
*addr
)
1110 struct name_hash
* nearest
= NULL
;
1113 if( sortlist_valid
== FALSE
)
1115 DEBUG_ResortSymbols();
1119 * Binary search to find closest symbol.
1122 high
= sorttab_nsym
;
1123 if( addr_sorttab
[0]->value
.addr
.seg
> addr
->seg
1124 || ( addr_sorttab
[0]->value
.addr
.seg
== addr
->seg
1125 && addr_sorttab
[0]->value
.addr
.off
> addr
->off
) )
1129 else if( addr_sorttab
[high
- 1]->value
.addr
.seg
< addr
->seg
1130 || ( addr_sorttab
[high
- 1]->value
.addr
.seg
== addr
->seg
1131 && addr_sorttab
[high
- 1]->value
.addr
.off
< addr
->off
) )
1133 nearest
= addr_sorttab
[high
- 1];
1139 mid
= (high
+ low
)/2;
1143 * See if there are any other entries that might also
1144 * have the same address, and would also have a line
1147 if( mid
> 0 && addr_sorttab
[mid
]->linetab
== NULL
)
1149 if( (addr_sorttab
[mid
- 1]->value
.addr
.seg
==
1150 addr_sorttab
[mid
]->value
.addr
.seg
)
1151 && (addr_sorttab
[mid
- 1]->value
.addr
.off
==
1152 addr_sorttab
[mid
]->value
.addr
.off
)
1153 && (addr_sorttab
[mid
- 1]->linetab
!= NULL
) )
1159 if( (mid
< sorttab_nsym
- 1)
1160 && (addr_sorttab
[mid
]->linetab
== NULL
) )
1162 if( (addr_sorttab
[mid
+ 1]->value
.addr
.seg
==
1163 addr_sorttab
[mid
]->value
.addr
.seg
)
1164 && (addr_sorttab
[mid
+ 1]->value
.addr
.off
==
1165 addr_sorttab
[mid
]->value
.addr
.off
)
1166 && (addr_sorttab
[mid
+ 1]->linetab
!= NULL
) )
1171 nearest
= addr_sorttab
[mid
];
1173 fprintf(stderr
, "Found %x:%x when looking for %x:%x %x %s\n",
1174 addr_sorttab
[mid
]->value
.addr
.seg
,
1175 addr_sorttab
[mid
]->value
.addr
.off
,
1176 addr
->seg
, addr
->off
,
1177 addr_sorttab
[mid
]->linetab
,
1178 addr_sorttab
[mid
]->name
);
1182 if( (addr_sorttab
[mid
]->value
.addr
.seg
< addr
->seg
)
1183 || ( addr_sorttab
[mid
]->value
.addr
.seg
== addr
->seg
1184 && addr_sorttab
[mid
]->value
.addr
.off
<= addr
->off
) )
1195 if (!nearest
) return FUNC_HAS_NO_LINES
;
1197 if( nearest
->flags
& SYM_STEP_THROUGH
)
1200 * This will cause us to keep single stepping until
1201 * we get to the other side somewhere.
1203 return NOT_ON_LINENUMBER
;
1206 if( (nearest
->flags
& SYM_TRAMPOLINE
) )
1209 * This will cause us to keep single stepping until
1210 * we get to the other side somewhere.
1212 return FUNC_IS_TRAMPOLINE
;
1215 if( nearest
->linetab
== NULL
)
1217 return FUNC_HAS_NO_LINES
;
1222 * We never want to stop on the first instruction of a function
1223 * even if it has it's own linenumber. Let the thing keep running
1224 * until it gets past the function prologue. We only do this if there
1225 * is more than one line number for the function, of course.
1227 if( nearest
->value
.addr
.off
== addr
->off
&& nearest
->n_lines
> 1 )
1229 return NOT_ON_LINENUMBER
;
1232 if( (nearest
->sourcefile
!= NULL
)
1233 && (addr
->off
- nearest
->value
.addr
.off
< 0x100000) )
1236 high
= nearest
->n_lines
;
1237 while ((high
- low
) > 1)
1239 mid
= (high
+ low
) / 2;
1240 if (addr
->off
< nearest
->linetab
[mid
].pc_offset
.off
) high
= mid
;
1243 if (addr
->off
== nearest
->linetab
[low
].pc_offset
.off
)
1244 return AT_LINENUMBER
;
1246 return NOT_ON_LINENUMBER
;
1249 return FUNC_HAS_NO_LINES
;
1252 /***********************************************************************
1255 * Find the symbol nearest to a given address.
1256 * Returns sourcefile name and line number in a format that the listing
1257 * handler can deal with.
1260 DEBUG_GetFuncInfo( struct list_id
* ret
, const char * filename
,
1265 struct name_hash
*nh
;
1267 for(nh
= name_hash_table
[name_hash(name
)]; nh
; nh
= nh
->next
)
1269 if( filename
!= NULL
)
1272 if( nh
->sourcefile
== NULL
)
1277 pnt
= strrchr(nh
->sourcefile
, '/');
1278 if( strcmp(nh
->sourcefile
, filename
) != 0
1279 && (pnt
== NULL
|| strcmp(pnt
+ 1, filename
) != 0) )
1284 if (!strcmp(nh
->name
, name
)) break;
1287 if (!nh
&& (name
[0] != '_'))
1290 strcpy(buffer
+1, name
);
1291 for(nh
= name_hash_table
[name_hash(buffer
)]; nh
; nh
= nh
->next
)
1293 if( filename
!= NULL
)
1295 if( nh
->sourcefile
== NULL
)
1300 pnt
= strrchr(nh
->sourcefile
, '/');
1301 if( strcmp(nh
->sourcefile
, filename
) != 0
1302 && (pnt
== NULL
|| strcmp(pnt
+ 1, filename
) != 0) )
1307 if (!strcmp(nh
->name
, buffer
)) break;
1313 if( filename
!= NULL
)
1315 fprintf(stderr
, "No such function %s in %s\n", name
, filename
);
1319 fprintf(stderr
, "No such function %s\n", name
);
1321 ret
->sourcefile
= NULL
;
1326 ret
->sourcefile
= nh
->sourcefile
;
1329 * Search for the specific line number. If we don't find it,
1330 * then return FALSE.
1332 if( nh
->linetab
== NULL
)
1338 ret
->line
= nh
->linetab
[0].line_number
;
1342 /***********************************************************************
1343 * DEBUG_GetStackSymbolValue
1345 * Get the address of a named symbol from the current stack frame.
1348 BOOL
DEBUG_GetStackSymbolValue( const char * name
, DBG_VALUE
*value
)
1350 struct name_hash
* curr_func
;
1355 if( DEBUG_GetCurrentFrame(&curr_func
, &eip
, &ebp
) == FALSE
)
1360 for(i
=0; i
< curr_func
->n_locals
; i
++ )
1363 * Test the range of validity of the local variable. This
1364 * comes up with RBRAC/LBRAC stabs in particular.
1366 if( (curr_func
->local_vars
[i
].pc_start
!= 0)
1367 && ((eip
- curr_func
->value
.addr
.off
)
1368 < curr_func
->local_vars
[i
].pc_start
) )
1373 if( (curr_func
->local_vars
[i
].pc_end
!= 0)
1374 && ((eip
- curr_func
->value
.addr
.off
)
1375 > curr_func
->local_vars
[i
].pc_end
) )
1380 if( strcmp(name
, curr_func
->local_vars
[i
].name
) == 0 )
1383 * OK, we found it. Now figure out what to do with this.
1385 if( curr_func
->local_vars
[i
].regno
!= 0 )
1388 * Register variable. Point to DEBUG_context field.
1390 value
->addr
.off
= ((DWORD
)&DEBUG_context
) +
1391 reg_ofs
[curr_func
->local_vars
[i
].regno
- 1];
1392 value
->cookie
= DV_HOST
;
1396 value
->addr
.off
= ebp
+ curr_func
->local_vars
[i
].offset
;
1397 value
->cookie
= DV_TARGET
;
1399 value
->addr
.seg
= 0;
1400 value
->type
= curr_func
->local_vars
[i
].type
;
1410 DEBUG_InfoLocals(void)
1412 struct name_hash
* curr_func
;
1419 if( DEBUG_GetCurrentFrame(&curr_func
, &eip
, &ebp
) == FALSE
)
1424 for(i
=0; i
< curr_func
->n_locals
; i
++ )
1427 * Test the range of validity of the local variable. This
1428 * comes up with RBRAC/LBRAC stabs in particular.
1430 if( (curr_func
->local_vars
[i
].pc_start
!= 0)
1431 && ((eip
- curr_func
->value
.addr
.off
)
1432 < curr_func
->local_vars
[i
].pc_start
) )
1437 if( (curr_func
->local_vars
[i
].pc_end
!= 0)
1438 && ((eip
- curr_func
->value
.addr
.off
)
1439 > curr_func
->local_vars
[i
].pc_end
) )
1444 if( curr_func
->local_vars
[i
].regno
!= 0 )
1446 ptr
= (unsigned int *)(((DWORD
)&DEBUG_context
)
1447 + reg_ofs
[curr_func
->local_vars
[i
].regno
- 1]);
1448 fprintf(stderr
, "%s:%s (optimized into register $%s) == 0x%8.8x\n",
1449 curr_func
->name
, curr_func
->local_vars
[i
].name
,
1450 reg_name
[curr_func
->local_vars
[i
].regno
- 1],
1455 DEBUG_READ_MEM_VERBOSE((void*)(ebp
+ curr_func
->local_vars
[i
].offset
),
1457 fprintf(stderr
, "%s:%s == 0x%8.8x\n",
1458 curr_func
->name
, curr_func
->local_vars
[i
].name
, val
);
1466 DEBUG_SetSymbolSize(struct name_hash
* sym
, unsigned int len
)
1468 sym
->symbol_size
= len
;
1474 DEBUG_SetSymbolBPOff(struct name_hash
* sym
, unsigned int off
)
1476 sym
->breakpoint_offset
= off
;
1482 DEBUG_GetSymbolAddr(struct name_hash
* sym
, DBG_ADDR
* addr
)
1485 *addr
= sym
->value
.addr
;
1490 int DEBUG_SetLocalSymbolType(struct wine_locals
* sym
, struct datatype
* type
)