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);
882 typedef struct tag_lmr{
885 struct tag_lmr* next;
886 } DBG_LoadedModuleRef;
894 static BOOL DEBUG_LEPHelper(const char* mod_name, BOOL is16, DBG_LEPData* lep)
896 static DBG_LoadedModuleRef* lmr = NULL;
897 DBG_LoadedModuleRef* p;
898 DBG_LoadedModuleRef** pp1;
899 DBG_LoadedModuleRef* p2;
900 int len = strlen(mod_name);
903 for (p = lmr; p; p = p->next) {
904 cmp = strcmp(p->module_name, mod_name);
916 if (lep->pfx) fprintf( stderr, lep->pfx );
917 fprintf( stderr, " " );
922 if ((lep->rowcount + len) > 76)
924 fprintf( stderr, "\n ");
927 fprintf( stderr, " %s", mod_name );
928 lep->rowcount += len + 1;
930 p = DBG_alloc(sizeof(*lmr));
931 p->module_name = DBG_strdup(mod_name);
935 for (pp1 = &lmr; *pp1; pp1 = &(*pp1)->next) {
936 if (strcmp((*pp1)->module_name, mod_name) > 0)
945 else if (*pp1 == NULL)
959 /***********************************************************************
960 * DEBUG_LoadEntryPoints
962 * Load the entry points of all the modules into the hash table.
964 int DEBUG_LoadEntryPoints(const char* pfx)
975 /* FIXME: we assume that a module is never removed from memory */
977 for (ok = ModuleFirst16(&entry); ok; ok = ModuleNext16(&entry))
979 if (!(pModule = NE_GetPtr( entry.hModule ))) continue;
980 if (!(pModule->flags & NE_FFLAGS_WIN32) && /* NE module */
981 DEBUG_LEPHelper( entry.szModule, TRUE, &lep ))
982 DEBUG_LoadEntryPoints16( entry.hModule, pModule, entry.szModule );
984 for (wm=PROCESS_Current()->modref_list;wm;wm=wm->next)
986 if (DEBUG_LEPHelper( wm->modname, FALSE, &lep ))
987 DEBUG_LoadEntryPoints32( wm->module, wm->modname );
989 if (lep.first) fprintf( stderr, "\n" );
995 DEBUG_AddLineNumber( struct name_hash * func, int line_num,
996 unsigned long offset )
1003 if( func->n_lines + 1 >= func->lines_alloc )
1005 func->lines_alloc += 64;
1006 func->linetab = DBG_realloc(func->linetab,
1007 func->lines_alloc * sizeof(WineLineNo));
1010 func->linetab[func->n_lines].line_number = line_num;
1011 func->linetab[func->n_lines].pc_offset.seg = func->addr.seg;
1012 func->linetab[func->n_lines].pc_offset.off = func->addr.off + offset;
1013 func->linetab[func->n_lines].pc_offset.type = NULL;
1018 struct wine_locals *
1019 DEBUG_AddLocal( struct name_hash * func, int regno,
1030 if( func->n_locals + 1 >= func->locals_alloc )
1032 func->locals_alloc += 32;
1033 func->local_vars = DBG_realloc(func->local_vars,
1034 func->locals_alloc * sizeof(WineLocals));
1037 func->local_vars[func->n_locals].regno = regno;
1038 func->local_vars[func->n_locals].offset = offset;
1039 func->local_vars[func->n_locals].pc_start = pc_start;
1040 func->local_vars[func->n_locals].pc_end = pc_end;
1041 func->local_vars[func->n_locals].name = DBG_strdup(name);
1042 func->local_vars[func->n_locals].type = NULL;
1045 return &func->local_vars[func->n_locals - 1];
1049 DEBUG_DumpHashInfo()
1053 struct name_hash *nh;
1056 * Utility function to dump stats about the hash table.
1058 for(i=0; i<NR_NAME_HASH; i++)
1061 for (nh = name_hash_table[i]; nh; nh = nh->next)
1065 fprintf(stderr, "Bucket %d: %d\n", i, depth);
1069 /***********************************************************************
1070 * DEBUG_CheckLinenoStatus
1072 * Find the symbol nearest to a given address.
1073 * If ebp is specified as non-zero, it means we should dump the argument
1074 * list into the string we return as well.
1076 int DEBUG_CheckLinenoStatus( const DBG_ADDR *addr)
1078 struct name_hash * nearest = NULL;
1081 if( sortlist_valid == FALSE )
1083 DEBUG_ResortSymbols();
1087 * Binary search to find closest symbol.
1090 high = sorttab_nsym;
1091 if( addr_sorttab[0]->addr.seg > addr->seg
1092 || ( addr_sorttab[0]->addr.seg == addr->seg
1093 && addr_sorttab[0]->addr.off > addr->off) )
1097 else if( addr_sorttab[high - 1]->addr.seg < addr->seg
1098 || ( addr_sorttab[high - 1]->addr.seg == addr->seg
1099 && addr_sorttab[high - 1]->addr.off < addr->off) )
1101 nearest = addr_sorttab[high - 1];
1107 mid = (high + low)/2;
1111 * See if there are any other entries that might also
1112 * have the same address, and would also have a line
1115 if( mid > 0 && addr_sorttab[mid]->linetab == NULL )
1117 if( (addr_sorttab[mid - 1]->addr.seg ==
1118 addr_sorttab[mid]->addr.seg)
1119 && (addr_sorttab[mid - 1]->addr.off ==
1120 addr_sorttab[mid]->addr.off)
1121 && (addr_sorttab[mid - 1]->linetab != NULL) )
1127 if( (mid < sorttab_nsym - 1)
1128 && (addr_sorttab[mid]->linetab == NULL) )
1130 if( (addr_sorttab[mid + 1]->addr.seg ==
1131 addr_sorttab[mid]->addr.seg)
1132 && (addr_sorttab[mid + 1]->addr.off ==
1133 addr_sorttab[mid]->addr.off)
1134 && (addr_sorttab[mid + 1]->linetab != NULL) )
1139 nearest = addr_sorttab[mid];
1141 fprintf(stderr, "Found %x:%x when looking for %x:%x %x %s\n",
1142 addr_sorttab[mid ]->addr.seg,
1143 addr_sorttab[mid ]->addr.off,
1144 addr->seg, addr->off,
1145 addr_sorttab[mid ]->linetab,
1146 addr_sorttab[mid ]->name);
1150 if( (addr_sorttab[mid]->addr.seg < addr->seg)
1151 || ( addr_sorttab[mid]->addr.seg == addr->seg
1152 && addr_sorttab[mid]->addr.off <= addr->off) )
1163 if (!nearest) return FUNC_HAS_NO_LINES;
1165 if( nearest->flags & SYM_STEP_THROUGH )
1168 * This will cause us to keep single stepping until
1169 * we get to the other side somewhere.
1171 return NOT_ON_LINENUMBER;
1174 if( (nearest->flags & SYM_TRAMPOLINE) )
1177 * This will cause us to keep single stepping until
1178 * we get to the other side somewhere.
1180 return FUNC_IS_TRAMPOLINE;
1183 if( nearest->linetab == NULL )
1185 return FUNC_HAS_NO_LINES;
1190 * We never want to stop on the first instruction of a function
1191 * even if it has it's own linenumber. Let the thing keep running
1192 * until it gets past the function prologue. We only do this if there
1193 * is more than one line number for the function, of course.
1195 if( nearest->addr.off == addr->off && nearest->n_lines > 1 )
1197 return NOT_ON_LINENUMBER;
1200 if( (nearest->sourcefile != NULL)
1201 && (addr->off - nearest->addr.off < 0x100000) )
1204 high = nearest->n_lines;
1205 while ((high - low) > 1)
1207 mid = (high + low) / 2;
1208 if (addr->off < nearest->linetab[mid].pc_offset.off) high = mid;
1211 if (addr->off == nearest->linetab[low].pc_offset.off)
1212 return AT_LINENUMBER;
1214 return NOT_ON_LINENUMBER;
1217 return FUNC_HAS_NO_LINES;
1220 /***********************************************************************
1223 * Find the symbol nearest to a given address.
1224 * Returns sourcefile name and line number in a format that the listing
1225 * handler can deal with.
1228 DEBUG_GetFuncInfo( struct list_id * ret, const char * filename,
1233 struct name_hash *nh;
1235 for(nh = name_hash_table[name_hash(name)]; nh; nh = nh->next)
1237 if( filename != NULL )
1240 if( nh->sourcefile == NULL )
1245 pnt = strrchr(nh->sourcefile, '/');
1246 if( strcmp(nh->sourcefile, filename) != 0
1247 && (pnt == NULL || strcmp(pnt + 1, filename) != 0) )
1252 if (!strcmp(nh->name, name)) break;
1255 if (!nh && (name[0] != '_'))
1258 strcpy(buffer+1, name);
1259 for(nh = name_hash_table[name_hash(buffer)]; nh; nh = nh->next)
1261 if( filename != NULL )
1263 if( nh->sourcefile == NULL )
1268 pnt = strrchr(nh->sourcefile, '/');
1269 if( strcmp(nh->sourcefile, filename) != 0
1270 && (pnt == NULL || strcmp(pnt + 1, filename) != 0) )
1275 if (!strcmp(nh->name, buffer)) break;
1281 if( filename != NULL )
1283 fprintf(stderr, "No such function %s in %s\n", name, filename);
1287 fprintf(stderr, "No such function %s\n", name);
1289 ret->sourcefile = NULL;
1294 ret->sourcefile = nh->sourcefile;
1297 * Search for the specific line number. If we don't find it,
1298 * then return FALSE.
1300 if( nh->linetab == NULL )
1306 ret->line = nh->linetab[0].line_number;
1310 /***********************************************************************
1311 * DEBUG_GetStackSymbolValue
1313 * Get the address of a named symbol from the current stack frame.
1316 BOOL DEBUG_GetStackSymbolValue( const char * name, DBG_ADDR *addr )
1318 struct name_hash * curr_func;
1323 if( DEBUG_GetCurrentFrame(&curr_func, &eip, &ebp) == FALSE )
1328 for(i=0; i < curr_func->n_locals; i++ )
1331 * Test the range of validity of the local variable. This
1332 * comes up with RBRAC/LBRAC stabs in particular.
1334 if( (curr_func->local_vars[i].pc_start != 0)
1335 && ((eip - curr_func->addr.off)
1336 < curr_func->local_vars[i].pc_start) )
1341 if( (curr_func->local_vars[i].pc_end != 0)
1342 && ((eip - curr_func->addr.off)
1343 > curr_func->local_vars[i].pc_end) )
1348 if( strcmp(name, curr_func->local_vars[i].name) == 0 )
1351 * OK, we found it. Now figure out what to do with this.
1353 /* FIXME: what if regno == 0 ($eax) */
1354 if( curr_func->local_vars[i].regno != 0 )
1357 * Register variable. Point to DEBUG_context field.
1360 addr->off = ((DWORD)&DEBUG_context) + reg_ofs[curr_func->local_vars[i].regno];
1361 addr->type = curr_func->local_vars[i].type;
1367 addr->off = ebp + curr_func->local_vars[i].offset;
1368 addr->type = curr_func->local_vars[i].type;
1379 struct name_hash * curr_func;
1386 if( DEBUG_GetCurrentFrame(&curr_func, &eip, &ebp) == FALSE )
1391 for(i=0; i < curr_func->n_locals; i++ )
1394 * Test the range of validity of the local variable. This
1395 * comes up with RBRAC/LBRAC stabs in particular.
1397 if( (curr_func->local_vars[i].pc_start != 0)
1398 && ((eip - curr_func->addr.off)
1399 < curr_func->local_vars[i].pc_start) )
1404 if( (curr_func->local_vars[i].pc_end != 0)
1405 && ((eip - curr_func->addr.off)
1406 > curr_func->local_vars[i].pc_end) )
1411 if( curr_func->local_vars[i].offset == 0 )
1413 ptr = (unsigned int *) (((DWORD)&DEBUG_context)
1414 + reg_ofs[curr_func->local_vars[i].regno]);
1415 fprintf(stderr, "%s:%s (optimized into register $%s) == 0x%8.8x\n",
1416 curr_func->name, curr_func->local_vars[i].name,
1417 reg_name[curr_func->local_vars[i].regno],
1422 ptr = (unsigned int *) (ebp + curr_func->local_vars[i].offset);
1423 fprintf(stderr, "%s:%s == 0x%8.8x\n",
1424 curr_func->name, curr_func->local_vars[i].name,
1435 DEBUG_SetSymbolSize(struct name_hash * sym, unsigned int len)
1437 sym->symbol_size = len;
1443 DEBUG_SetSymbolBPOff(struct name_hash * sym, unsigned int off)
1445 sym->breakpoint_offset = off;
1451 DEBUG_GetSymbolAddr(struct name_hash * sym, DBG_ADDR * addr)
1459 int DEBUG_SetLocalSymbolType(struct wine_locals * sym, struct datatype * type)