2 * File hash.c - generate hash tables for Wine debugger symbols
4 * Copyright (C) 1993, Eric Youngdale.
12 #include <sys/types.h>
16 #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 BOOL32
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
)
156 addr_sorttab
= (struct name_hash
**) xrealloc(addr_sorttab
,
157 nsym
* sizeof(struct name_hash
*));
160 for(i
=0; i
<NR_NAME_HASH
; i
++)
162 for (nh
= name_hash_table
[i
]; nh
; nh
= nh
->next
)
164 addr_sorttab
[nsym
++] = nh
;
168 qsort(addr_sorttab
, nsym
,
169 sizeof(struct name_hash
*), DEBUG_cmp_sym
);
170 sortlist_valid
= TRUE
;
174 /***********************************************************************
177 * Add a symbol to the table.
180 DEBUG_AddSymbol( const char * name
, const DBG_ADDR
*addr
, const char * source
,
183 struct name_hash
* new;
184 struct name_hash
*nh
;
185 static char prev_source
[PATH_MAX
] = {'\0', };
186 static char * prev_duped_source
= NULL
;
190 hash
= name_hash(name
);
191 for (nh
= name_hash_table
[hash
]; nh
; nh
= nh
->next
)
193 if( ((nh
->flags
& SYM_INVALID
) != 0) && strcmp(name
, nh
->name
) == 0 )
195 nh
->addr
.off
= addr
->off
;
196 nh
->addr
.seg
= addr
->seg
;
197 if( nh
->addr
.type
== NULL
&& addr
->type
!= NULL
)
199 nh
->addr
.type
= addr
->type
;
201 nh
->flags
&= ~SYM_INVALID
;
204 if (nh
->addr
.seg
== addr
->seg
&&
205 nh
->addr
.off
== addr
->off
&&
206 strcmp(name
, nh
->name
) == 0 )
213 * First see if we already have an entry for this symbol. If so
214 * return it, so we don't end up with duplicates.
217 new = (struct name_hash
*) xmalloc(sizeof(struct name_hash
));
219 new->name
= xstrdup(name
);
224 * This is an enhancement to reduce memory consumption. The idea
225 * is that we duplicate a given string only once. This is a big
226 * win if there are lots of symbols defined in a given source file.
228 if( strcmp(source
, prev_source
) == 0 )
230 new->sourcefile
= prev_duped_source
;
234 strcpy(prev_source
, source
);
235 prev_duped_source
= new->sourcefile
= xstrdup(source
);
240 new->sourcefile
= NULL
;
244 new->lines_alloc
= 0;
248 new->locals_alloc
= 0;
249 new->local_vars
= NULL
;
254 /* Now insert into the hash table */
255 new->next
= name_hash_table
[hash
];
256 name_hash_table
[hash
] = new;
259 * Check some heuristics based upon the file name to see whether
260 * we want to step through this guy or not. These are machine generated
261 * assembly files that are used to translate between the MS way of
262 * calling things and the GCC way of calling things. In general we
263 * always want to step through.
267 c
= strrchr(source
, '.');
268 if( c
!= NULL
&& strcmp(c
, ".s") == 0 )
270 c
= strrchr(source
, '/');
274 if( (strcmp(c
, "callfrom16.s") == 0)
275 || (strcmp(c
, "callto16.s") == 0)
276 || (strcmp(c
, "call32.s") == 0) )
278 new->flags
|= SYM_TRAMPOLINE
;
284 sortlist_valid
= FALSE
;
288 BOOL32
DEBUG_Normalize(struct name_hash
* nh
)
292 * We aren't adding any more locals or linenumbers to this function.
293 * Free any spare memory that we might have allocated.
300 if( nh
->n_locals
!= nh
->locals_alloc
)
302 nh
->locals_alloc
= nh
->n_locals
;
303 nh
->local_vars
= xrealloc(nh
->local_vars
,
304 nh
->locals_alloc
* sizeof(WineLocals
));
307 if( nh
->n_lines
!= nh
->lines_alloc
)
309 nh
->lines_alloc
= nh
->n_lines
;
310 nh
->linetab
= xrealloc(nh
->linetab
,
311 nh
->lines_alloc
* sizeof(WineLineNo
));
317 /***********************************************************************
318 * DEBUG_GetSymbolValue
320 * Get the address of a named symbol.
322 BOOL32
DEBUG_GetSymbolValue( const char * name
, const int lineno
,
323 DBG_ADDR
*addr
, int bp_flag
)
326 struct name_hash
*nh
;
328 for(nh
= name_hash_table
[name_hash(name
)]; nh
; nh
= nh
->next
)
330 if( (nh
->flags
& SYM_INVALID
) != 0 )
335 if (!strcmp(nh
->name
, name
)) break;
338 if (!nh
&& (name
[0] != '_'))
341 strcpy(buffer
+1, name
);
342 for(nh
= name_hash_table
[name_hash(buffer
)]; nh
; nh
= nh
->next
)
344 if( (nh
->flags
& SYM_INVALID
) != 0 )
348 if (!strcmp(nh
->name
, buffer
)) break;
353 * If we don't have anything here, then try and see if this
354 * is a local symbol to the current stack frame. No matter
355 * what, we have nothing more to do, so we let that function
356 * decide what we ultimately return.
360 return DEBUG_GetStackSymbolValue(name
, addr
);
363 return DEBUG_GetLineNumberAddr( nh
, lineno
, addr
, bp_flag
);
366 /***********************************************************************
367 * DEBUG_GetLineNumberAddr
369 * Get the address of a named symbol.
371 BOOL32
DEBUG_GetLineNumberAddr( struct name_hash
* nh
, const int lineno
,
372 DBG_ADDR
*addr
, int bp_flag
)
381 addr
->off
+= nh
->breakpoint_offset
;
387 * Search for the specific line number. If we don't find it,
390 if( nh
->linetab
== NULL
)
395 for(i
=0; i
< nh
->n_lines
; i
++ )
397 if( nh
->linetab
[i
].line_number
== lineno
)
399 *addr
= nh
->linetab
[i
].pc_offset
;
405 * This specific line number not found.
414 /***********************************************************************
415 * DEBUG_SetSymbolValue
417 * Set the address of a named symbol.
419 BOOL32
DEBUG_SetSymbolValue( const char * name
, const DBG_ADDR
*addr
)
422 struct name_hash
*nh
;
424 for(nh
= name_hash_table
[name_hash(name
)]; nh
; nh
= nh
->next
)
425 if (!strcmp(nh
->name
, name
)) break;
427 if (!nh
&& (name
[0] != '_'))
430 strcpy(buffer
+1, name
);
431 for(nh
= name_hash_table
[name_hash(buffer
)]; nh
; nh
= nh
->next
)
432 if (!strcmp(nh
->name
, buffer
)) break;
435 if (!nh
) return FALSE
;
437 nh
->flags
&= SYM_INVALID
;
438 DBG_FIX_ADDR_SEG( &nh
->addr
, DS_reg(&DEBUG_context
) );
443 /***********************************************************************
444 * DEBUG_FindNearestSymbol
446 * Find the symbol nearest to a given address.
447 * If ebp is specified as non-zero, it means we should dump the argument
448 * list into the string we return as well.
450 const char * DEBUG_FindNearestSymbol( const DBG_ADDR
*addr
, int flag
,
451 struct name_hash
** rtn
,
453 struct list_id
* source
)
455 static char name_buffer
[MAX_PATH
+ 256];
456 static char arglist
[1024];
457 static char argtmp
[256];
458 struct name_hash
* nearest
= NULL
;
462 char * lineinfo
, *sourcefile
;
473 source
->sourcefile
= NULL
;
477 if( sortlist_valid
== FALSE
)
479 DEBUG_ResortSymbols();
482 if( sortlist_valid
== FALSE
)
488 * FIXME - use the binary search that we added to
489 * the function DEBUG_CheckLinenoStatus. Better yet, we should
490 * probably keep some notion of the current function so we don't
491 * have to search every time.
494 * Binary search to find closest symbol.
498 if( addr_sorttab
[0]->addr
.seg
> addr
->seg
499 || ( addr_sorttab
[0]->addr
.seg
== addr
->seg
500 && addr_sorttab
[0]->addr
.off
> addr
->off
) )
504 else if( addr_sorttab
[high
- 1]->addr
.seg
< addr
->seg
505 || ( addr_sorttab
[high
- 1]->addr
.seg
== addr
->seg
506 && addr_sorttab
[high
- 1]->addr
.off
< addr
->off
) )
508 nearest
= addr_sorttab
[high
- 1];
514 mid
= (high
+ low
)/2;
518 * See if there are any other entries that might also
519 * have the same address, and would also have a line
522 if( mid
> 0 && addr_sorttab
[mid
]->linetab
== NULL
)
524 if( (addr_sorttab
[mid
- 1]->addr
.seg
==
525 addr_sorttab
[mid
]->addr
.seg
)
526 && (addr_sorttab
[mid
- 1]->addr
.off
==
527 addr_sorttab
[mid
]->addr
.off
)
528 && (addr_sorttab
[mid
- 1]->linetab
!= NULL
) )
534 if( (mid
< sorttab_nsym
- 1)
535 && (addr_sorttab
[mid
]->linetab
== NULL
) )
537 if( (addr_sorttab
[mid
+ 1]->addr
.seg
==
538 addr_sorttab
[mid
]->addr
.seg
)
539 && (addr_sorttab
[mid
+ 1]->addr
.off
==
540 addr_sorttab
[mid
]->addr
.off
)
541 && (addr_sorttab
[mid
+ 1]->linetab
!= NULL
) )
546 nearest
= addr_sorttab
[mid
];
548 fprintf(stderr
, "Found %x:%x when looking for %x:%x %x %s\n",
549 addr_sorttab
[mid
]->addr
.seg
,
550 addr_sorttab
[mid
]->addr
.off
,
551 addr
->seg
, addr
->off
,
552 addr_sorttab
[mid
]->linetab
,
553 addr_sorttab
[mid
]->name
);
557 if( (addr_sorttab
[mid
]->addr
.seg
< addr
->seg
)
558 || ( addr_sorttab
[mid
]->addr
.seg
== addr
->seg
559 && addr_sorttab
[mid
]->addr
.off
<= addr
->off
) )
570 if (!nearest
) return NULL
;
578 * Fill in the relevant bits to the structure so that we can
579 * locate the source and line for this bit of code.
583 source
->sourcefile
= nearest
->sourcefile
;
584 if( nearest
->linetab
== NULL
)
590 source
->line
= nearest
->linetab
[0].line_number
;
598 * Prepare to display the argument list. If ebp is specified, it is
599 * the framepointer for the function in question. If not specified,
600 * we don't want the arglist.
602 memset(arglist
, '\0', sizeof(arglist
));
605 for(i
=0; i
< nearest
->n_locals
; i
++ )
608 * If this is a register (offset == 0) or a local
609 * variable, we don't want to know about it.
611 if( nearest
->local_vars
[i
].offset
<= 0 )
616 ptr
= (unsigned int *) (ebp
+ nearest
->local_vars
[i
].offset
);
617 if( arglist
[0] == '\0' )
623 strcat(arglist
, ", ");
626 sprintf(argtmp
, "%s=0x%x", nearest
->local_vars
[i
].name
,
628 strcat(arglist
, argtmp
);
630 if( arglist
[0] == '(' )
632 strcat(arglist
, ")");
636 if( (nearest
->sourcefile
!= NULL
) && (flag
== TRUE
)
637 && (addr
->off
- nearest
->addr
.off
< 0x100000) )
641 * Try and find the nearest line number to the current offset.
643 if( nearest
->linetab
!= NULL
)
646 high
= nearest
->n_lines
;
647 while ((high
- low
) > 1)
649 mid
= (high
+ low
) / 2;
650 if (addr
->off
< nearest
->linetab
[mid
].pc_offset
.off
)
655 lineno
= nearest
->linetab
[low
].line_number
;
660 sprintf(linebuff
, ":%d", lineno
);
664 source
->line
= lineno
;
668 /* Remove the path from the file name */
669 sourcefile
= strrchr( nearest
->sourcefile
, '/' );
670 if (!sourcefile
) sourcefile
= nearest
->sourcefile
;
673 if (addr
->off
== nearest
->addr
.off
)
674 sprintf( name_buffer
, "%s%s [%s%s]", nearest
->name
,
675 arglist
, sourcefile
, lineinfo
);
677 sprintf( name_buffer
, "%s+0x%lx%s [%s%s]", nearest
->name
,
678 addr
->off
- nearest
->addr
.off
,
679 arglist
, sourcefile
, lineinfo
);
683 if (addr
->off
== nearest
->addr
.off
)
684 sprintf( name_buffer
, "%s%s", nearest
->name
, arglist
);
686 if (addr
->seg
&& (nearest
->addr
.seg
!=addr
->seg
))
689 sprintf( name_buffer
, "%s+0x%lx%s", nearest
->name
,
690 addr
->off
- nearest
->addr
.off
, arglist
);
697 /***********************************************************************
698 * DEBUG_ReadSymbolTable
700 * Read a symbol file into the hash table.
702 void DEBUG_ReadSymbolTable( const char * filename
)
705 DBG_ADDR addr
= { 0, 0 };
712 if (!(symbolfile
= fopen(filename
, "r")))
714 fprintf( stderr
, "Unable to open symbol table %s\n", filename
);
718 fprintf( stderr
, "Reading symbols from file %s\n", filename
);
722 fgets( buffer
, sizeof(buffer
), symbolfile
);
723 if (feof(symbolfile
)) break;
725 /* Strip any text after a # sign (i.e. comments) */
728 if(*cpnt
++ == '#') { *cpnt
= 0; break; }
730 /* Quietly ignore any lines that have just whitespace */
734 if(*cpnt
!= ' ' && *cpnt
!= '\t') break;
737 if (!(*cpnt
) || *cpnt
== '\n') continue;
739 nargs
= sscanf(buffer
, "%lx %c %s", &addr
.off
, &type
, name
);
740 DEBUG_AddSymbol( name
, &addr
, NULL
, SYM_WINE
);
746 /***********************************************************************
747 * DEBUG_LoadEntryPoints16
749 * Load the entry points of a Win16 module into the hash table.
751 static void DEBUG_LoadEntryPoints16( HMODULE16 hModule
, NE_MODULE
*pModule
,
758 /* First search the resident names */
760 unsigned char *cpnt
= (unsigned char *)pModule
+ pModule
->name_table
;
763 cpnt
+= *cpnt
+ 1 + sizeof(WORD
);
764 sprintf( buffer
, "%s.%.*s", name
, *cpnt
, cpnt
+ 1 );
765 if ((address
= NE_GetEntryPoint(hModule
, *(WORD
*)(cpnt
+ *cpnt
+ 1))))
767 addr
.seg
= HIWORD(address
);
768 addr
.off
= LOWORD(address
);
770 DEBUG_AddSymbol( buffer
, &addr
, NULL
, SYM_WIN32
| SYM_FUNC
);
774 /* Now search the non-resident names table */
776 if (!pModule
->nrname_handle
) return; /* No non-resident table */
777 cpnt
= (char *)GlobalLock16( pModule
->nrname_handle
);
780 cpnt
+= *cpnt
+ 1 + sizeof(WORD
);
781 sprintf( buffer
, "%s.%.*s", name
, *cpnt
, cpnt
+ 1 );
782 if ((address
= NE_GetEntryPoint(hModule
, *(WORD
*)(cpnt
+ *cpnt
+ 1))))
784 addr
.seg
= HIWORD(address
);
785 addr
.off
= LOWORD(address
);
787 DEBUG_AddSymbol( buffer
, &addr
, NULL
, SYM_WIN32
| SYM_FUNC
);
793 /***********************************************************************
794 * DEBUG_LoadEntryPoints32
796 * Load the entry points of a Win32 module into the hash table.
798 static void DEBUG_LoadEntryPoints32( HMODULE32 hModule
, const char *name
)
800 #define RVA(x) (hModule+(DWORD)(x))
805 IMAGE_SECTION_HEADER
*pe_seg
;
806 IMAGE_EXPORT_DIRECTORY
*exports
;
807 IMAGE_DATA_DIRECTORY
*dir
;
815 /* Add start of DLL */
818 DEBUG_AddSymbol( name
, &addr
, NULL
, SYM_WIN32
| SYM_FUNC
);
820 /* Add entry point */
822 sprintf( buffer
, "%s.EntryPoint", name
);
823 addr
.off
= (DWORD
)RVA_PTR( hModule
, OptionalHeader
.AddressOfEntryPoint
);
824 DEBUG_AddSymbol( buffer
, &addr
, NULL
, SYM_WIN32
| SYM_FUNC
);
826 /* Add start of sections */
828 pe_seg
= PE_SECTIONS(hModule
);
829 for (i
= 0; i
< PE_HEADER(hModule
)->FileHeader
.NumberOfSections
; i
++)
831 sprintf( buffer
, "%s.%s", name
, pe_seg
->Name
);
832 addr
.off
= RVA(pe_seg
->VirtualAddress
);
833 DEBUG_AddSymbol( buffer
, &addr
, NULL
, SYM_WIN32
| SYM_FUNC
);
837 /* Add exported functions */
839 dir
= &PE_HEADER(hModule
)->OptionalHeader
.
840 DataDirectory
[IMAGE_DIRECTORY_ENTRY_EXPORT
];
843 exports
= (IMAGE_EXPORT_DIRECTORY
*)RVA( dir
->VirtualAddress
);
844 ordinals
= (WORD
*)RVA( exports
->AddressOfNameOrdinals
);
845 names
= (const char **)RVA( exports
->AddressOfNames
);
846 functions
= (void **)RVA( exports
->AddressOfFunctions
);
848 for (i
= 0; i
< exports
->NumberOfNames
; i
++)
850 if (!names
[i
]) continue;
851 sprintf( buffer
, "%s.%s", name
, (char *)RVA(names
[i
]) );
852 addr
.off
= RVA( functions
[ordinals
[i
]] );
853 DEBUG_AddSymbol( buffer
, &addr
, NULL
, SYM_WIN32
| SYM_FUNC
);
856 for (i
= 0; i
< exports
->NumberOfFunctions
; i
++)
858 if (!functions
[i
]) continue;
859 /* Check if we already added it with a name */
860 for (j
= 0; j
< exports
->NumberOfNames
; j
++)
861 if ((ordinals
[j
] == i
) && names
[j
]) break;
862 if (j
< exports
->NumberOfNames
) continue;
863 sprintf( buffer
, "%s.%ld", name
, i
+ exports
->Base
);
864 addr
.off
= (DWORD
)RVA( functions
[i
] );
865 DEBUG_AddSymbol( buffer
, &addr
, NULL
, SYM_WIN32
| SYM_FUNC
);
868 DEBUG_RegisterDebugInfo(hModule
, name
);
873 /***********************************************************************
874 * DEBUG_LoadEntryPoints
876 * Load the entry points of all the modules into the hash table.
878 void DEBUG_LoadEntryPoints(void)
886 fprintf( stderr
, " " );
887 for (ok
= ModuleFirst(&entry
); ok
; ok
= ModuleNext(&entry
))
889 if (!(pModule
= NE_GetPtr( entry
.hModule
))) continue;
890 if (!(pModule
->flags
& NE_FFLAGS_WIN32
)) /* NE module */
892 if ((rowcount
+ strlen(entry
.szModule
)) > 76)
894 fprintf( stderr
,"\n ");
897 fprintf( stderr
, " %s", entry
.szModule
);
898 rowcount
+= strlen(entry
.szModule
) + 1;
900 DEBUG_LoadEntryPoints16( entry
.hModule
, pModule
, entry
.szModule
);
903 for (wm
=PROCESS_Current()->modref_list
;wm
;wm
=wm
->next
)
905 if ((rowcount
+ strlen(wm
->modname
)) > 76)
907 fprintf( stderr
,"\n ");
910 fprintf( stderr
, " %s", wm
->modname
);
911 rowcount
+= strlen(wm
->modname
) + 1;
912 DEBUG_LoadEntryPoints32( wm
->module
, wm
->modname
);
914 fprintf( stderr
, "\n" );
919 DEBUG_AddLineNumber( struct name_hash
* func
, int line_num
,
920 unsigned long offset
)
927 if( func
->n_lines
+ 1 >= func
->lines_alloc
)
929 func
->lines_alloc
+= 64;
930 func
->linetab
= xrealloc(func
->linetab
,
931 func
->lines_alloc
* sizeof(WineLineNo
));
934 func
->linetab
[func
->n_lines
].line_number
= line_num
;
935 func
->linetab
[func
->n_lines
].pc_offset
.seg
= func
->addr
.seg
;
936 func
->linetab
[func
->n_lines
].pc_offset
.off
= func
->addr
.off
+ offset
;
937 func
->linetab
[func
->n_lines
].pc_offset
.type
= NULL
;
943 DEBUG_AddLocal( struct name_hash
* func
, int regno
,
954 if( func
->n_locals
+ 1 >= func
->locals_alloc
)
956 func
->locals_alloc
+= 32;
957 func
->local_vars
= xrealloc(func
->local_vars
,
958 func
->locals_alloc
* sizeof(WineLocals
));
961 func
->local_vars
[func
->n_locals
].regno
= regno
;
962 func
->local_vars
[func
->n_locals
].offset
= offset
;
963 func
->local_vars
[func
->n_locals
].pc_start
= pc_start
;
964 func
->local_vars
[func
->n_locals
].pc_end
= pc_end
;
965 func
->local_vars
[func
->n_locals
].name
= xstrdup(name
);
966 func
->local_vars
[func
->n_locals
].type
= NULL
;
969 return &func
->local_vars
[func
->n_locals
- 1];
977 struct name_hash
*nh
;
980 * Utility function to dump stats about the hash table.
982 for(i
=0; i
<NR_NAME_HASH
; i
++)
985 for (nh
= name_hash_table
[i
]; nh
; nh
= nh
->next
)
989 fprintf(stderr
, "Bucket %d: %d\n", i
, depth
);
993 /***********************************************************************
994 * DEBUG_CheckLinenoStatus
996 * Find the symbol nearest to a given address.
997 * If ebp is specified as non-zero, it means we should dump the argument
998 * list into the string we return as well.
1000 int DEBUG_CheckLinenoStatus( const DBG_ADDR
*addr
)
1002 struct name_hash
* nearest
= NULL
;
1005 if( sortlist_valid
== FALSE
)
1007 DEBUG_ResortSymbols();
1011 * Binary search to find closest symbol.
1014 high
= sorttab_nsym
;
1015 if( addr_sorttab
[0]->addr
.seg
> addr
->seg
1016 || ( addr_sorttab
[0]->addr
.seg
== addr
->seg
1017 && addr_sorttab
[0]->addr
.off
> addr
->off
) )
1021 else if( addr_sorttab
[high
- 1]->addr
.seg
< addr
->seg
1022 || ( addr_sorttab
[high
- 1]->addr
.seg
== addr
->seg
1023 && addr_sorttab
[high
- 1]->addr
.off
< addr
->off
) )
1025 nearest
= addr_sorttab
[high
- 1];
1031 mid
= (high
+ low
)/2;
1035 * See if there are any other entries that might also
1036 * have the same address, and would also have a line
1039 if( mid
> 0 && addr_sorttab
[mid
]->linetab
== NULL
)
1041 if( (addr_sorttab
[mid
- 1]->addr
.seg
==
1042 addr_sorttab
[mid
]->addr
.seg
)
1043 && (addr_sorttab
[mid
- 1]->addr
.off
==
1044 addr_sorttab
[mid
]->addr
.off
)
1045 && (addr_sorttab
[mid
- 1]->linetab
!= NULL
) )
1051 if( (mid
< sorttab_nsym
- 1)
1052 && (addr_sorttab
[mid
]->linetab
== NULL
) )
1054 if( (addr_sorttab
[mid
+ 1]->addr
.seg
==
1055 addr_sorttab
[mid
]->addr
.seg
)
1056 && (addr_sorttab
[mid
+ 1]->addr
.off
==
1057 addr_sorttab
[mid
]->addr
.off
)
1058 && (addr_sorttab
[mid
+ 1]->linetab
!= NULL
) )
1063 nearest
= addr_sorttab
[mid
];
1065 fprintf(stderr
, "Found %x:%x when looking for %x:%x %x %s\n",
1066 addr_sorttab
[mid
]->addr
.seg
,
1067 addr_sorttab
[mid
]->addr
.off
,
1068 addr
->seg
, addr
->off
,
1069 addr_sorttab
[mid
]->linetab
,
1070 addr_sorttab
[mid
]->name
);
1074 if( (addr_sorttab
[mid
]->addr
.seg
< addr
->seg
)
1075 || ( addr_sorttab
[mid
]->addr
.seg
== addr
->seg
1076 && addr_sorttab
[mid
]->addr
.off
<= addr
->off
) )
1087 if (!nearest
) return FUNC_HAS_NO_LINES
;
1089 if( nearest
->flags
& SYM_STEP_THROUGH
)
1092 * This will cause us to keep single stepping until
1093 * we get to the other side somewhere.
1095 return NOT_ON_LINENUMBER
;
1098 if( (nearest
->flags
& SYM_TRAMPOLINE
) )
1101 * This will cause us to keep single stepping until
1102 * we get to the other side somewhere.
1104 return FUNC_IS_TRAMPOLINE
;
1107 if( nearest
->linetab
== NULL
)
1109 return FUNC_HAS_NO_LINES
;
1114 * We never want to stop on the first instruction of a function
1115 * even if it has it's own linenumber. Let the thing keep running
1116 * until it gets past the function prologue. We only do this if there
1117 * is more than one line number for the function, of course.
1119 if( nearest
->addr
.off
== addr
->off
&& nearest
->n_lines
> 1 )
1121 return NOT_ON_LINENUMBER
;
1124 if( (nearest
->sourcefile
!= NULL
)
1125 && (addr
->off
- nearest
->addr
.off
< 0x100000) )
1128 high
= nearest
->n_lines
;
1129 while ((high
- low
) > 1)
1131 mid
= (high
+ low
) / 2;
1132 if (addr
->off
< nearest
->linetab
[mid
].pc_offset
.off
) high
= mid
;
1135 if (addr
->off
== nearest
->linetab
[low
].pc_offset
.off
)
1136 return AT_LINENUMBER
;
1138 return NOT_ON_LINENUMBER
;
1141 return FUNC_HAS_NO_LINES
;
1144 /***********************************************************************
1147 * Find the symbol nearest to a given address.
1148 * Returns sourcefile name and line number in a format that the listing
1149 * handler can deal with.
1152 DEBUG_GetFuncInfo( struct list_id
* ret
, const char * filename
,
1157 struct name_hash
*nh
;
1159 for(nh
= name_hash_table
[name_hash(name
)]; nh
; nh
= nh
->next
)
1161 if( filename
!= NULL
)
1164 if( nh
->sourcefile
== NULL
)
1169 pnt
= strrchr(nh
->sourcefile
, '/');
1170 if( strcmp(nh
->sourcefile
, filename
) != 0
1171 && (pnt
== NULL
|| strcmp(pnt
+ 1, filename
) != 0) )
1176 if (!strcmp(nh
->name
, name
)) break;
1179 if (!nh
&& (name
[0] != '_'))
1182 strcpy(buffer
+1, name
);
1183 for(nh
= name_hash_table
[name_hash(buffer
)]; nh
; nh
= nh
->next
)
1185 if( filename
!= NULL
)
1187 if( nh
->sourcefile
== NULL
)
1192 pnt
= strrchr(nh
->sourcefile
, '/');
1193 if( strcmp(nh
->sourcefile
, filename
) != 0
1194 && (pnt
== NULL
|| strcmp(pnt
+ 1, filename
) != 0) )
1199 if (!strcmp(nh
->name
, buffer
)) break;
1205 if( filename
!= NULL
)
1207 fprintf(stderr
, "No such function %s in %s\n", name
, filename
);
1211 fprintf(stderr
, "No such function %s\n", name
);
1213 ret
->sourcefile
= NULL
;
1218 ret
->sourcefile
= nh
->sourcefile
;
1221 * Search for the specific line number. If we don't find it,
1222 * then return FALSE.
1224 if( nh
->linetab
== NULL
)
1230 ret
->line
= nh
->linetab
[0].line_number
;
1234 /***********************************************************************
1235 * DEBUG_GetStackSymbolValue
1237 * Get the address of a named symbol from the current stack frame.
1240 BOOL32
DEBUG_GetStackSymbolValue( const char * name
, DBG_ADDR
*addr
)
1242 struct name_hash
* curr_func
;
1247 if( DEBUG_GetCurrentFrame(&curr_func
, &eip
, &ebp
) == FALSE
)
1252 for(i
=0; i
< curr_func
->n_locals
; i
++ )
1255 * Test the range of validity of the local variable. This
1256 * comes up with RBRAC/LBRAC stabs in particular.
1258 if( (curr_func
->local_vars
[i
].pc_start
!= 0)
1259 && ((eip
- curr_func
->addr
.off
)
1260 < curr_func
->local_vars
[i
].pc_start
) )
1265 if( (curr_func
->local_vars
[i
].pc_end
!= 0)
1266 && ((eip
- curr_func
->addr
.off
)
1267 > curr_func
->local_vars
[i
].pc_end
) )
1272 if( strcmp(name
, curr_func
->local_vars
[i
].name
) == 0 )
1275 * OK, we found it. Now figure out what to do with this.
1277 /* FIXME: what if regno == 0 ($eax) */
1278 if( curr_func
->local_vars
[i
].regno
!= 0 )
1281 * Register variable. Point to DEBUG_context field.
1284 addr
->off
= ((DWORD
)&DEBUG_context
) + reg_ofs
[curr_func
->local_vars
[i
].regno
];
1285 addr
->type
= curr_func
->local_vars
[i
].type
;
1291 addr
->off
= ebp
+ curr_func
->local_vars
[i
].offset
;
1292 addr
->type
= curr_func
->local_vars
[i
].type
;
1303 struct name_hash
* curr_func
;
1310 if( DEBUG_GetCurrentFrame(&curr_func
, &eip
, &ebp
) == FALSE
)
1315 for(i
=0; i
< curr_func
->n_locals
; i
++ )
1318 * Test the range of validity of the local variable. This
1319 * comes up with RBRAC/LBRAC stabs in particular.
1321 if( (curr_func
->local_vars
[i
].pc_start
!= 0)
1322 && ((eip
- curr_func
->addr
.off
)
1323 < curr_func
->local_vars
[i
].pc_start
) )
1328 if( (curr_func
->local_vars
[i
].pc_end
!= 0)
1329 && ((eip
- curr_func
->addr
.off
)
1330 > curr_func
->local_vars
[i
].pc_end
) )
1335 if( curr_func
->local_vars
[i
].offset
== 0 )
1337 ptr
= (unsigned int *) (((DWORD
)&DEBUG_context
)
1338 + reg_ofs
[curr_func
->local_vars
[i
].regno
]);
1339 fprintf(stderr
, "%s:%s (optimized into register $%s) == 0x%8.8x\n",
1340 curr_func
->name
, curr_func
->local_vars
[i
].name
,
1341 reg_name
[curr_func
->local_vars
[i
].regno
],
1346 ptr
= (unsigned int *) (ebp
+ curr_func
->local_vars
[i
].offset
);
1347 fprintf(stderr
, "%s:%s == 0x%8.8x\n",
1348 curr_func
->name
, curr_func
->local_vars
[i
].name
,
1359 DEBUG_SetSymbolSize(struct name_hash
* sym
, unsigned int len
)
1361 sym
->symbol_size
= len
;
1367 DEBUG_SetSymbolBPOff(struct name_hash
* sym
, unsigned int off
)
1369 sym
->breakpoint_offset
= off
;
1375 DEBUG_GetSymbolAddr(struct name_hash
* sym
, DBG_ADDR
* addr
)
1383 int DEBUG_SetLocalSymbolType(struct wine_locals
* sym
, struct datatype
* type
)