2 * File hash.c - generate hash tables for Wine debugger symbols
4 * Copyright (C) 1993, Eric Youngdale.
13 #include <sys/types.h>
17 #include "selectors.h"
21 #define NR_NAME_HASH 16384
23 #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
)
42 struct name_hash
* next
; /* Used to look up within name hash */
48 WineLocals
* local_vars
;
56 unsigned short breakpoint_offset
;
57 unsigned int symbol_size
;
61 static BOOL
DEBUG_GetStackSymbolValue( const char * name
, DBG_ADDR
*addr
);
62 static int sortlist_valid
= FALSE
;
64 static int sorttab_nsym
;
65 static struct name_hash
** addr_sorttab
= NULL
;
67 static struct name_hash
* name_hash_table
[NR_NAME_HASH
];
69 static unsigned int name_hash( const char * name
)
71 unsigned int hash
= 0;
79 hash
= (hash
<< 4) + *p
++;
81 if( (tmp
= (hash
& 0xf0000000)) )
87 return hash
% NR_NAME_HASH
;
91 DEBUG_cmp_sym(const void * p1
, const void * p2
)
93 struct name_hash
** name1
= (struct name_hash
**) p1
;
94 struct name_hash
** name2
= (struct name_hash
**) p2
;
96 if( ((*name1
)->flags
& SYM_INVALID
) != 0 )
101 if( ((*name2
)->flags
& SYM_INVALID
) != 0 )
106 if( (*name1
)->addr
.seg
> (*name2
)->addr
.seg
)
111 if( (*name1
)->addr
.seg
< (*name2
)->addr
.seg
)
116 if( (*name1
)->addr
.off
> (*name2
)->addr
.off
)
121 if( (*name1
)->addr
.off
< (*name2
)->addr
.off
)
129 /***********************************************************************
130 * DEBUG_ResortSymbols
132 * Rebuild sorted list of symbols.
136 DEBUG_ResortSymbols()
138 struct name_hash
*nh
;
142 for(i
=0; i
<NR_NAME_HASH
; i
++)
144 for (nh
= name_hash_table
[i
]; nh
; nh
= nh
->next
)
146 if( (nh
->flags
& SYM_INVALID
) == 0 )
149 fprintf( stderr
, "Symbol %s is invalid\n", nh
->name
);
159 addr_sorttab
= (struct name_hash
**) DBG_realloc(addr_sorttab
,
160 nsym
* sizeof(struct name_hash
*));
163 for(i
=0; i
<NR_NAME_HASH
; i
++)
165 for (nh
= name_hash_table
[i
]; nh
; nh
= nh
->next
)
167 if( (nh
->flags
& SYM_INVALID
) == 0 )
168 addr_sorttab
[nsym
++] = nh
;
172 qsort(addr_sorttab
, nsym
,
173 sizeof(struct name_hash
*), DEBUG_cmp_sym
);
174 sortlist_valid
= TRUE
;
178 /***********************************************************************
181 * Add a symbol to the table.
184 DEBUG_AddSymbol( const char * name
, const DBG_ADDR
*addr
, const char * source
,
187 struct name_hash
* new;
188 struct name_hash
*nh
;
189 static char prev_source
[PATH_MAX
] = {'\0', };
190 static char * prev_duped_source
= NULL
;
194 hash
= name_hash(name
);
195 for (nh
= name_hash_table
[hash
]; nh
; nh
= nh
->next
)
197 if( ((nh
->flags
& SYM_INVALID
) != 0) && strcmp(name
, nh
->name
) == 0 )
199 nh
->addr
.off
= addr
->off
;
200 nh
->addr
.seg
= addr
->seg
;
201 if( nh
->addr
.type
== NULL
&& addr
->type
!= NULL
)
203 nh
->addr
.type
= addr
->type
;
205 /* it may happen that the same symbol is defined in several compilation
206 * units, but the linker decides to merge it into a single instance.
207 * in that case, we don't clear the invalid flag for all the compilation
208 * units (N_GSYM), and wait to get the symbol from the symtab
210 if ((flags
& SYM_INVALID
) == 0)
211 nh
->flags
&= ~SYM_INVALID
;
214 if (nh
->addr
.seg
== addr
->seg
&&
215 nh
->addr
.off
== addr
->off
&&
216 strcmp(name
, nh
->name
) == 0 )
223 * First see if we already have an entry for this symbol. If so
224 * return it, so we don't end up with duplicates.
227 new = (struct name_hash
*) DBG_alloc(sizeof(struct name_hash
));
229 new->name
= DBG_strdup(name
);
234 * This is an enhancement to reduce memory consumption. The idea
235 * is that we duplicate a given string only once. This is a big
236 * win if there are lots of symbols defined in a given source file.
238 if( strcmp(source
, prev_source
) == 0 )
240 new->sourcefile
= prev_duped_source
;
244 strcpy(prev_source
, source
);
245 prev_duped_source
= new->sourcefile
= DBG_strdup(source
);
250 new->sourcefile
= NULL
;
254 new->lines_alloc
= 0;
258 new->locals_alloc
= 0;
259 new->local_vars
= NULL
;
264 /* Now insert into the hash table */
265 new->next
= name_hash_table
[hash
];
266 name_hash_table
[hash
] = new;
269 * Check some heuristics based upon the file name to see whether
270 * we want to step through this guy or not. These are machine generated
271 * assembly files that are used to translate between the MS way of
272 * calling things and the GCC way of calling things. In general we
273 * always want to step through.
277 c
= strrchr(source
, '.');
278 if( c
!= NULL
&& strcmp(c
, ".s") == 0 )
280 c
= strrchr(source
, '/');
284 if( (strcmp(c
, "callfrom16.s") == 0)
285 || (strcmp(c
, "callto16.s") == 0)
286 || (strcmp(c
, "call32.s") == 0) )
288 new->flags
|= SYM_TRAMPOLINE
;
294 sortlist_valid
= FALSE
;
298 BOOL
DEBUG_Normalize(struct name_hash
* nh
)
302 * We aren't adding any more locals or linenumbers to this function.
303 * Free any spare memory that we might have allocated.
310 if( nh
->n_locals
!= nh
->locals_alloc
)
312 nh
->locals_alloc
= nh
->n_locals
;
313 nh
->local_vars
= DBG_realloc(nh
->local_vars
,
314 nh
->locals_alloc
* sizeof(WineLocals
));
317 if( nh
->n_lines
!= nh
->lines_alloc
)
319 nh
->lines_alloc
= nh
->n_lines
;
320 nh
->linetab
= DBG_realloc(nh
->linetab
,
321 nh
->lines_alloc
* sizeof(WineLineNo
));
327 /***********************************************************************
328 * DEBUG_GetSymbolValue
330 * Get the address of a named symbol.
332 BOOL
DEBUG_GetSymbolValue( const char * name
, const int lineno
,
333 DBG_ADDR
*addr
, int bp_flag
)
336 struct name_hash
*nh
;
338 for(nh
= name_hash_table
[name_hash(name
)]; nh
; nh
= nh
->next
)
340 if( (nh
->flags
& SYM_INVALID
) != 0 )
345 if (!strcmp(nh
->name
, name
)) break;
348 if (!nh
&& (name
[0] != '_'))
351 strcpy(buffer
+1, name
);
352 for(nh
= name_hash_table
[name_hash(buffer
)]; nh
; nh
= nh
->next
)
354 if( (nh
->flags
& SYM_INVALID
) != 0 )
358 if (!strcmp(nh
->name
, buffer
)) break;
363 * If we don't have anything here, then try and see if this
364 * is a local symbol to the current stack frame. No matter
365 * what, we have nothing more to do, so we let that function
366 * decide what we ultimately return.
370 return DEBUG_GetStackSymbolValue(name
, addr
);
373 return DEBUG_GetLineNumberAddr( nh
, lineno
, addr
, bp_flag
);
376 /***********************************************************************
377 * DEBUG_GetLineNumberAddr
379 * Get the address of a named symbol.
381 BOOL
DEBUG_GetLineNumberAddr( struct name_hash
* nh
, const int lineno
,
382 DBG_ADDR
*addr
, int bp_flag
)
391 addr
->off
+= nh
->breakpoint_offset
;
397 * Search for the specific line number. If we don't find it,
400 if( nh
->linetab
== NULL
)
405 for(i
=0; i
< nh
->n_lines
; i
++ )
407 if( nh
->linetab
[i
].line_number
== lineno
)
409 *addr
= nh
->linetab
[i
].pc_offset
;
415 * This specific line number not found.
424 /***********************************************************************
425 * DEBUG_SetSymbolValue
427 * Set the address of a named symbol.
429 BOOL
DEBUG_SetSymbolValue( const char * name
, const DBG_ADDR
*addr
)
432 struct name_hash
*nh
;
434 for(nh
= name_hash_table
[name_hash(name
)]; nh
; nh
= nh
->next
)
435 if (!strcmp(nh
->name
, name
)) break;
437 if (!nh
&& (name
[0] != '_'))
440 strcpy(buffer
+1, name
);
441 for(nh
= name_hash_table
[name_hash(buffer
)]; nh
; nh
= nh
->next
)
442 if (!strcmp(nh
->name
, buffer
)) break;
445 if (!nh
) return FALSE
;
447 nh
->flags
&= SYM_INVALID
;
448 DBG_FIX_ADDR_SEG( &nh
->addr
, DS_reg(&DEBUG_context
) );
453 /***********************************************************************
454 * DEBUG_FindNearestSymbol
456 * Find the symbol nearest to a given address.
457 * If ebp is specified as non-zero, it means we should dump the argument
458 * list into the string we return as well.
460 const char * DEBUG_FindNearestSymbol( const DBG_ADDR
*addr
, int flag
,
461 struct name_hash
** rtn
,
463 struct list_id
* source
)
465 static char name_buffer
[MAX_PATH
+ 256];
466 static char arglist
[1024];
467 static char argtmp
[256];
468 struct name_hash
* nearest
= NULL
;
472 char * lineinfo
, *sourcefile
;
483 source
->sourcefile
= NULL
;
487 if( sortlist_valid
== FALSE
)
489 DEBUG_ResortSymbols();
492 if( sortlist_valid
== FALSE
)
498 * FIXME - use the binary search that we added to
499 * the function DEBUG_CheckLinenoStatus. Better yet, we should
500 * probably keep some notion of the current function so we don't
501 * have to search every time.
504 * Binary search to find closest symbol.
508 if( addr_sorttab
[0]->addr
.seg
> addr
->seg
509 || ( addr_sorttab
[0]->addr
.seg
== addr
->seg
510 && addr_sorttab
[0]->addr
.off
> addr
->off
) )
514 else if( addr_sorttab
[high
- 1]->addr
.seg
< addr
->seg
515 || ( addr_sorttab
[high
- 1]->addr
.seg
== addr
->seg
516 && addr_sorttab
[high
- 1]->addr
.off
< addr
->off
) )
518 nearest
= addr_sorttab
[high
- 1];
524 mid
= (high
+ low
)/2;
528 * See if there are any other entries that might also
529 * have the same address, and would also have a line
532 if( mid
> 0 && addr_sorttab
[mid
]->linetab
== NULL
)
534 if( (addr_sorttab
[mid
- 1]->addr
.seg
==
535 addr_sorttab
[mid
]->addr
.seg
)
536 && (addr_sorttab
[mid
- 1]->addr
.off
==
537 addr_sorttab
[mid
]->addr
.off
)
538 && (addr_sorttab
[mid
- 1]->linetab
!= NULL
) )
544 if( (mid
< sorttab_nsym
- 1)
545 && (addr_sorttab
[mid
]->linetab
== NULL
) )
547 if( (addr_sorttab
[mid
+ 1]->addr
.seg
==
548 addr_sorttab
[mid
]->addr
.seg
)
549 && (addr_sorttab
[mid
+ 1]->addr
.off
==
550 addr_sorttab
[mid
]->addr
.off
)
551 && (addr_sorttab
[mid
+ 1]->linetab
!= NULL
) )
556 nearest
= addr_sorttab
[mid
];
558 fprintf(stderr
, "Found %x:%x when looking for %x:%x %x %s\n",
559 addr_sorttab
[mid
]->addr
.seg
,
560 addr_sorttab
[mid
]->addr
.off
,
561 addr
->seg
, addr
->off
,
562 addr_sorttab
[mid
]->linetab
,
563 addr_sorttab
[mid
]->name
);
567 if( (addr_sorttab
[mid
]->addr
.seg
< addr
->seg
)
568 || ( addr_sorttab
[mid
]->addr
.seg
== addr
->seg
569 && addr_sorttab
[mid
]->addr
.off
<= addr
->off
) )
580 if (!nearest
) return NULL
;
588 * Fill in the relevant bits to the structure so that we can
589 * locate the source and line for this bit of code.
593 source
->sourcefile
= nearest
->sourcefile
;
594 if( nearest
->linetab
== NULL
)
600 source
->line
= nearest
->linetab
[0].line_number
;
608 * Prepare to display the argument list. If ebp is specified, it is
609 * the framepointer for the function in question. If not specified,
610 * we don't want the arglist.
612 memset(arglist
, '\0', sizeof(arglist
));
615 for(i
=0; i
< nearest
->n_locals
; i
++ )
618 * If this is a register (offset == 0) or a local
619 * variable, we don't want to know about it.
621 if( nearest
->local_vars
[i
].offset
<= 0 )
626 ptr
= (unsigned int *) (ebp
+ nearest
->local_vars
[i
].offset
);
627 if( arglist
[0] == '\0' )
633 strcat(arglist
, ", ");
636 sprintf(argtmp
, "%s=0x%x", nearest
->local_vars
[i
].name
,
638 strcat(arglist
, argtmp
);
640 if( arglist
[0] == '(' )
642 strcat(arglist
, ")");
646 if( (nearest
->sourcefile
!= NULL
) && (flag
== TRUE
)
647 && (addr
->off
- nearest
->addr
.off
< 0x100000) )
651 * Try and find the nearest line number to the current offset.
653 if( nearest
->linetab
!= NULL
)
656 high
= nearest
->n_lines
;
657 while ((high
- low
) > 1)
659 mid
= (high
+ low
) / 2;
660 if (addr
->off
< nearest
->linetab
[mid
].pc_offset
.off
)
665 lineno
= nearest
->linetab
[low
].line_number
;
670 sprintf(linebuff
, ":%d", lineno
);
674 source
->line
= lineno
;
678 /* Remove the path from the file name */
679 sourcefile
= strrchr( nearest
->sourcefile
, '/' );
680 if (!sourcefile
) sourcefile
= nearest
->sourcefile
;
683 if (addr
->off
== nearest
->addr
.off
)
684 sprintf( name_buffer
, "%s%s [%s%s]", nearest
->name
,
685 arglist
, sourcefile
, lineinfo
);
687 sprintf( name_buffer
, "%s+0x%lx%s [%s%s]", nearest
->name
,
688 addr
->off
- nearest
->addr
.off
,
689 arglist
, sourcefile
, lineinfo
);
693 if (addr
->off
== nearest
->addr
.off
)
694 sprintf( name_buffer
, "%s%s", nearest
->name
, arglist
);
696 if (addr
->seg
&& (nearest
->addr
.seg
!=addr
->seg
))
699 sprintf( name_buffer
, "%s+0x%lx%s", nearest
->name
,
700 addr
->off
- nearest
->addr
.off
, arglist
);
707 /***********************************************************************
708 * DEBUG_ReadSymbolTable
710 * Read a symbol file into the hash table.
712 void DEBUG_ReadSymbolTable( const char * filename
)
715 DBG_ADDR addr
= { 0, 0 };
722 if (!(symbolfile
= fopen(filename
, "r")))
724 fprintf( stderr
, "Unable to open symbol table %s\n", filename
);
728 fprintf( stderr
, "Reading symbols from file %s\n", filename
);
732 fgets( buffer
, sizeof(buffer
), symbolfile
);
733 if (feof(symbolfile
)) break;
735 /* Strip any text after a # sign (i.e. comments) */
738 if(*cpnt
++ == '#') { *cpnt
= 0; break; }
740 /* Quietly ignore any lines that have just whitespace */
744 if(*cpnt
!= ' ' && *cpnt
!= '\t') break;
747 if (!(*cpnt
) || *cpnt
== '\n') continue;
749 nargs
= sscanf(buffer
, "%lx %c %s", &addr
.off
, &type
, name
);
750 DEBUG_AddSymbol( name
, &addr
, NULL
, SYM_WINE
);
756 /***********************************************************************
757 * DEBUG_LoadEntryPoints16
759 * Load the entry points of a Win16 module into the hash table.
761 static void DEBUG_LoadEntryPoints16( HMODULE16 hModule
, NE_MODULE
*pModule
,
768 /* First search the resident names */
770 unsigned char *cpnt
= (unsigned char *)pModule
+ pModule
->name_table
;
773 cpnt
+= *cpnt
+ 1 + sizeof(WORD
);
774 sprintf( buffer
, "%s.%.*s", name
, *cpnt
, cpnt
+ 1 );
775 if ((address
= NE_GetEntryPoint(hModule
, *(WORD
*)(cpnt
+ *cpnt
+ 1))))
777 addr
.seg
= HIWORD(address
);
778 addr
.off
= LOWORD(address
);
780 DEBUG_AddSymbol( buffer
, &addr
, NULL
, SYM_WIN32
| SYM_FUNC
);
784 /* Now search the non-resident names table */
786 if (!pModule
->nrname_handle
) return; /* No non-resident table */
787 cpnt
= (char *)GlobalLock16( pModule
->nrname_handle
);
790 cpnt
+= *cpnt
+ 1 + sizeof(WORD
);
791 sprintf( buffer
, "%s.%.*s", name
, *cpnt
, cpnt
+ 1 );
792 if ((address
= NE_GetEntryPoint(hModule
, *(WORD
*)(cpnt
+ *cpnt
+ 1))))
794 addr
.seg
= HIWORD(address
);
795 addr
.off
= LOWORD(address
);
797 DEBUG_AddSymbol( buffer
, &addr
, NULL
, SYM_WIN32
| SYM_FUNC
);
803 /***********************************************************************
804 * DEBUG_LoadEntryPoints32
806 * Load the entry points of a Win32 module into the hash table.
808 static void DEBUG_LoadEntryPoints32( HMODULE hModule
, const char *name
)
810 #define RVA(x) (hModule+(DWORD)(x))
815 IMAGE_SECTION_HEADER
*pe_seg
;
816 IMAGE_EXPORT_DIRECTORY
*exports
;
817 IMAGE_DATA_DIRECTORY
*dir
;
825 /* Add start of DLL */
828 DEBUG_AddSymbol( name
, &addr
, NULL
, SYM_WIN32
| SYM_FUNC
);
830 /* Add entry point */
832 sprintf( buffer
, "%s.EntryPoint", name
);
833 addr
.off
= (DWORD
)RVA_PTR( hModule
, OptionalHeader
.AddressOfEntryPoint
);
834 DEBUG_AddSymbol( buffer
, &addr
, NULL
, SYM_WIN32
| SYM_FUNC
);
836 /* Add start of sections */
838 pe_seg
= PE_SECTIONS(hModule
);
839 for (i
= 0; i
< PE_HEADER(hModule
)->FileHeader
.NumberOfSections
; i
++)
841 sprintf( buffer
, "%s.%s", name
, pe_seg
->Name
);
842 addr
.off
= RVA(pe_seg
->VirtualAddress
);
843 DEBUG_AddSymbol( buffer
, &addr
, NULL
, SYM_WIN32
| SYM_FUNC
);
847 /* Add exported functions */
849 dir
= &PE_HEADER(hModule
)->OptionalHeader
.
850 DataDirectory
[IMAGE_DIRECTORY_ENTRY_EXPORT
];
853 exports
= (IMAGE_EXPORT_DIRECTORY
*)RVA( dir
->VirtualAddress
);
854 ordinals
= (WORD
*)RVA( exports
->AddressOfNameOrdinals
);
855 names
= (const char **)RVA( exports
->AddressOfNames
);
856 functions
= (void **)RVA( exports
->AddressOfFunctions
);
858 for (i
= 0; i
< exports
->NumberOfNames
; i
++)
860 if (!names
[i
]) continue;
861 sprintf( buffer
, "%s.%s", name
, (char *)RVA(names
[i
]) );
862 addr
.off
= RVA( functions
[ordinals
[i
]] );
863 DEBUG_AddSymbol( buffer
, &addr
, NULL
, SYM_WIN32
| SYM_FUNC
);
866 for (i
= 0; i
< exports
->NumberOfFunctions
; i
++)
868 if (!functions
[i
]) continue;
869 /* Check if we already added it with a name */
870 for (j
= 0; j
< exports
->NumberOfNames
; j
++)
871 if ((ordinals
[j
] == i
) && names
[j
]) break;
872 if (j
< exports
->NumberOfNames
) continue;
873 sprintf( buffer
, "%s.%ld", name
, i
+ exports
->Base
);
874 addr
.off
= (DWORD
)RVA( functions
[i
] );
875 DEBUG_AddSymbol( buffer
, &addr
, NULL
, SYM_WIN32
| SYM_FUNC
);
878 DEBUG_RegisterDebugInfo(hModule
, name
);
883 /***********************************************************************
884 * DEBUG_LoadEntryPoints
886 * Load the entry points of all the modules into the hash table.
888 void DEBUG_LoadEntryPoints(void)
896 fprintf( stderr
, " " );
897 for (ok
= ModuleFirst16(&entry
); ok
; ok
= ModuleNext16(&entry
))
899 if (!(pModule
= NE_GetPtr( entry
.hModule
))) continue;
900 if (!(pModule
->flags
& NE_FFLAGS_WIN32
)) /* NE module */
902 if ((rowcount
+ strlen(entry
.szModule
)) > 76)
904 fprintf( stderr
,"\n ");
907 fprintf( stderr
, " %s", entry
.szModule
);
908 rowcount
+= strlen(entry
.szModule
) + 1;
910 DEBUG_LoadEntryPoints16( entry
.hModule
, pModule
, entry
.szModule
);
913 for (wm
=PROCESS_Current()->modref_list
;wm
;wm
=wm
->next
)
915 if ((rowcount
+ strlen(wm
->modname
)) > 76)
917 fprintf( stderr
,"\n ");
920 fprintf( stderr
, " %s", wm
->modname
);
921 rowcount
+= strlen(wm
->modname
) + 1;
922 DEBUG_LoadEntryPoints32( wm
->module
, wm
->modname
);
924 fprintf( stderr
, "\n" );
929 DEBUG_AddLineNumber( struct name_hash
* func
, int line_num
,
930 unsigned long offset
)
937 if( func
->n_lines
+ 1 >= func
->lines_alloc
)
939 func
->lines_alloc
+= 64;
940 func
->linetab
= DBG_realloc(func
->linetab
,
941 func
->lines_alloc
* sizeof(WineLineNo
));
944 func
->linetab
[func
->n_lines
].line_number
= line_num
;
945 func
->linetab
[func
->n_lines
].pc_offset
.seg
= func
->addr
.seg
;
946 func
->linetab
[func
->n_lines
].pc_offset
.off
= func
->addr
.off
+ offset
;
947 func
->linetab
[func
->n_lines
].pc_offset
.type
= NULL
;
953 DEBUG_AddLocal( struct name_hash
* func
, int regno
,
964 if( func
->n_locals
+ 1 >= func
->locals_alloc
)
966 func
->locals_alloc
+= 32;
967 func
->local_vars
= DBG_realloc(func
->local_vars
,
968 func
->locals_alloc
* sizeof(WineLocals
));
971 func
->local_vars
[func
->n_locals
].regno
= regno
;
972 func
->local_vars
[func
->n_locals
].offset
= offset
;
973 func
->local_vars
[func
->n_locals
].pc_start
= pc_start
;
974 func
->local_vars
[func
->n_locals
].pc_end
= pc_end
;
975 func
->local_vars
[func
->n_locals
].name
= DBG_strdup(name
);
976 func
->local_vars
[func
->n_locals
].type
= NULL
;
979 return &func
->local_vars
[func
->n_locals
- 1];
987 struct name_hash
*nh
;
990 * Utility function to dump stats about the hash table.
992 for(i
=0; i
<NR_NAME_HASH
; i
++)
995 for (nh
= name_hash_table
[i
]; nh
; nh
= nh
->next
)
999 fprintf(stderr
, "Bucket %d: %d\n", i
, depth
);
1003 /***********************************************************************
1004 * DEBUG_CheckLinenoStatus
1006 * Find the symbol nearest to a given address.
1007 * If ebp is specified as non-zero, it means we should dump the argument
1008 * list into the string we return as well.
1010 int DEBUG_CheckLinenoStatus( const DBG_ADDR
*addr
)
1012 struct name_hash
* nearest
= NULL
;
1015 if( sortlist_valid
== FALSE
)
1017 DEBUG_ResortSymbols();
1021 * Binary search to find closest symbol.
1024 high
= sorttab_nsym
;
1025 if( addr_sorttab
[0]->addr
.seg
> addr
->seg
1026 || ( addr_sorttab
[0]->addr
.seg
== addr
->seg
1027 && addr_sorttab
[0]->addr
.off
> addr
->off
) )
1031 else if( addr_sorttab
[high
- 1]->addr
.seg
< addr
->seg
1032 || ( addr_sorttab
[high
- 1]->addr
.seg
== addr
->seg
1033 && addr_sorttab
[high
- 1]->addr
.off
< addr
->off
) )
1035 nearest
= addr_sorttab
[high
- 1];
1041 mid
= (high
+ low
)/2;
1045 * See if there are any other entries that might also
1046 * have the same address, and would also have a line
1049 if( mid
> 0 && addr_sorttab
[mid
]->linetab
== NULL
)
1051 if( (addr_sorttab
[mid
- 1]->addr
.seg
==
1052 addr_sorttab
[mid
]->addr
.seg
)
1053 && (addr_sorttab
[mid
- 1]->addr
.off
==
1054 addr_sorttab
[mid
]->addr
.off
)
1055 && (addr_sorttab
[mid
- 1]->linetab
!= NULL
) )
1061 if( (mid
< sorttab_nsym
- 1)
1062 && (addr_sorttab
[mid
]->linetab
== NULL
) )
1064 if( (addr_sorttab
[mid
+ 1]->addr
.seg
==
1065 addr_sorttab
[mid
]->addr
.seg
)
1066 && (addr_sorttab
[mid
+ 1]->addr
.off
==
1067 addr_sorttab
[mid
]->addr
.off
)
1068 && (addr_sorttab
[mid
+ 1]->linetab
!= NULL
) )
1073 nearest
= addr_sorttab
[mid
];
1075 fprintf(stderr
, "Found %x:%x when looking for %x:%x %x %s\n",
1076 addr_sorttab
[mid
]->addr
.seg
,
1077 addr_sorttab
[mid
]->addr
.off
,
1078 addr
->seg
, addr
->off
,
1079 addr_sorttab
[mid
]->linetab
,
1080 addr_sorttab
[mid
]->name
);
1084 if( (addr_sorttab
[mid
]->addr
.seg
< addr
->seg
)
1085 || ( addr_sorttab
[mid
]->addr
.seg
== addr
->seg
1086 && addr_sorttab
[mid
]->addr
.off
<= addr
->off
) )
1097 if (!nearest
) return FUNC_HAS_NO_LINES
;
1099 if( nearest
->flags
& SYM_STEP_THROUGH
)
1102 * This will cause us to keep single stepping until
1103 * we get to the other side somewhere.
1105 return NOT_ON_LINENUMBER
;
1108 if( (nearest
->flags
& SYM_TRAMPOLINE
) )
1111 * This will cause us to keep single stepping until
1112 * we get to the other side somewhere.
1114 return FUNC_IS_TRAMPOLINE
;
1117 if( nearest
->linetab
== NULL
)
1119 return FUNC_HAS_NO_LINES
;
1124 * We never want to stop on the first instruction of a function
1125 * even if it has it's own linenumber. Let the thing keep running
1126 * until it gets past the function prologue. We only do this if there
1127 * is more than one line number for the function, of course.
1129 if( nearest
->addr
.off
== addr
->off
&& nearest
->n_lines
> 1 )
1131 return NOT_ON_LINENUMBER
;
1134 if( (nearest
->sourcefile
!= NULL
)
1135 && (addr
->off
- nearest
->addr
.off
< 0x100000) )
1138 high
= nearest
->n_lines
;
1139 while ((high
- low
) > 1)
1141 mid
= (high
+ low
) / 2;
1142 if (addr
->off
< nearest
->linetab
[mid
].pc_offset
.off
) high
= mid
;
1145 if (addr
->off
== nearest
->linetab
[low
].pc_offset
.off
)
1146 return AT_LINENUMBER
;
1148 return NOT_ON_LINENUMBER
;
1151 return FUNC_HAS_NO_LINES
;
1154 /***********************************************************************
1157 * Find the symbol nearest to a given address.
1158 * Returns sourcefile name and line number in a format that the listing
1159 * handler can deal with.
1162 DEBUG_GetFuncInfo( struct list_id
* ret
, const char * filename
,
1167 struct name_hash
*nh
;
1169 for(nh
= name_hash_table
[name_hash(name
)]; nh
; nh
= nh
->next
)
1171 if( filename
!= NULL
)
1174 if( nh
->sourcefile
== NULL
)
1179 pnt
= strrchr(nh
->sourcefile
, '/');
1180 if( strcmp(nh
->sourcefile
, filename
) != 0
1181 && (pnt
== NULL
|| strcmp(pnt
+ 1, filename
) != 0) )
1186 if (!strcmp(nh
->name
, name
)) break;
1189 if (!nh
&& (name
[0] != '_'))
1192 strcpy(buffer
+1, name
);
1193 for(nh
= name_hash_table
[name_hash(buffer
)]; nh
; nh
= nh
->next
)
1195 if( filename
!= NULL
)
1197 if( nh
->sourcefile
== NULL
)
1202 pnt
= strrchr(nh
->sourcefile
, '/');
1203 if( strcmp(nh
->sourcefile
, filename
) != 0
1204 && (pnt
== NULL
|| strcmp(pnt
+ 1, filename
) != 0) )
1209 if (!strcmp(nh
->name
, buffer
)) break;
1215 if( filename
!= NULL
)
1217 fprintf(stderr
, "No such function %s in %s\n", name
, filename
);
1221 fprintf(stderr
, "No such function %s\n", name
);
1223 ret
->sourcefile
= NULL
;
1228 ret
->sourcefile
= nh
->sourcefile
;
1231 * Search for the specific line number. If we don't find it,
1232 * then return FALSE.
1234 if( nh
->linetab
== NULL
)
1240 ret
->line
= nh
->linetab
[0].line_number
;
1244 /***********************************************************************
1245 * DEBUG_GetStackSymbolValue
1247 * Get the address of a named symbol from the current stack frame.
1250 BOOL
DEBUG_GetStackSymbolValue( const char * name
, DBG_ADDR
*addr
)
1252 struct name_hash
* curr_func
;
1257 if( DEBUG_GetCurrentFrame(&curr_func
, &eip
, &ebp
) == FALSE
)
1262 for(i
=0; i
< curr_func
->n_locals
; i
++ )
1265 * Test the range of validity of the local variable. This
1266 * comes up with RBRAC/LBRAC stabs in particular.
1268 if( (curr_func
->local_vars
[i
].pc_start
!= 0)
1269 && ((eip
- curr_func
->addr
.off
)
1270 < curr_func
->local_vars
[i
].pc_start
) )
1275 if( (curr_func
->local_vars
[i
].pc_end
!= 0)
1276 && ((eip
- curr_func
->addr
.off
)
1277 > curr_func
->local_vars
[i
].pc_end
) )
1282 if( strcmp(name
, curr_func
->local_vars
[i
].name
) == 0 )
1285 * OK, we found it. Now figure out what to do with this.
1287 /* FIXME: what if regno == 0 ($eax) */
1288 if( curr_func
->local_vars
[i
].regno
!= 0 )
1291 * Register variable. Point to DEBUG_context field.
1294 addr
->off
= ((DWORD
)&DEBUG_context
) + reg_ofs
[curr_func
->local_vars
[i
].regno
];
1295 addr
->type
= curr_func
->local_vars
[i
].type
;
1301 addr
->off
= ebp
+ curr_func
->local_vars
[i
].offset
;
1302 addr
->type
= curr_func
->local_vars
[i
].type
;
1313 struct name_hash
* curr_func
;
1320 if( DEBUG_GetCurrentFrame(&curr_func
, &eip
, &ebp
) == FALSE
)
1325 for(i
=0; i
< curr_func
->n_locals
; i
++ )
1328 * Test the range of validity of the local variable. This
1329 * comes up with RBRAC/LBRAC stabs in particular.
1331 if( (curr_func
->local_vars
[i
].pc_start
!= 0)
1332 && ((eip
- curr_func
->addr
.off
)
1333 < curr_func
->local_vars
[i
].pc_start
) )
1338 if( (curr_func
->local_vars
[i
].pc_end
!= 0)
1339 && ((eip
- curr_func
->addr
.off
)
1340 > curr_func
->local_vars
[i
].pc_end
) )
1345 if( curr_func
->local_vars
[i
].offset
== 0 )
1347 ptr
= (unsigned int *) (((DWORD
)&DEBUG_context
)
1348 + reg_ofs
[curr_func
->local_vars
[i
].regno
]);
1349 fprintf(stderr
, "%s:%s (optimized into register $%s) == 0x%8.8x\n",
1350 curr_func
->name
, curr_func
->local_vars
[i
].name
,
1351 reg_name
[curr_func
->local_vars
[i
].regno
],
1356 ptr
= (unsigned int *) (ebp
+ curr_func
->local_vars
[i
].offset
);
1357 fprintf(stderr
, "%s:%s == 0x%8.8x\n",
1358 curr_func
->name
, curr_func
->local_vars
[i
].name
,
1369 DEBUG_SetSymbolSize(struct name_hash
* sym
, unsigned int len
)
1371 sym
->symbol_size
= len
;
1377 DEBUG_SetSymbolBPOff(struct name_hash
* sym
, unsigned int off
)
1379 sym
->breakpoint_offset
= off
;
1385 DEBUG_GetSymbolAddr(struct name_hash
* sym
, DBG_ADDR
* addr
)
1393 int DEBUG_SetLocalSymbolType(struct wine_locals
* sym
, struct datatype
* type
)