2 * File hash.c - generate hash tables for Wine debugger symbols
4 * Copyright (C) 1993, Eric Youngdale.
13 #include <sys/types.h>
16 #define NR_NAME_HASH 16384
18 #define PATH_MAX _MAX_PATH
22 static char * reg_name
[] =
24 "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi"
27 static unsigned reg_ofs
[] =
29 FIELD_OFFSET(CONTEXT
, Eax
), FIELD_OFFSET(CONTEXT
, Ecx
),
30 FIELD_OFFSET(CONTEXT
, Edx
), FIELD_OFFSET(CONTEXT
, Ebx
),
31 FIELD_OFFSET(CONTEXT
, Esp
), FIELD_OFFSET(CONTEXT
, Ebp
),
32 FIELD_OFFSET(CONTEXT
, Esi
), FIELD_OFFSET(CONTEXT
, Edi
)
35 static char * reg_name
[] = { NULL
}; /* FIXME */
36 static unsigned reg_ofs
[] = { 0 };
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_VALUE
*value
);
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
)->value
.addr
.seg
> (*name2
)->value
.addr
.seg
)
111 if( (*name1
)->value
.addr
.seg
< (*name2
)->value
.addr
.seg
)
116 if( (*name1
)->value
.addr
.off
> (*name2
)->value
.addr
.off
)
121 if( (*name1
)->value
.addr
.off
< (*name2
)->value
.addr
.off
)
129 /***********************************************************************
130 * DEBUG_ResortSymbols
132 * Rebuild sorted list of symbols.
136 DEBUG_ResortSymbols(void)
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 DEBUG_Printf( DBG_CHN_MESG
, "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_VALUE
*value
, 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 assert(value
->cookie
== DV_TARGET
|| value
->cookie
== DV_HOST
);
196 hash
= name_hash(name
);
197 for (nh
= name_hash_table
[hash
]; nh
; nh
= nh
->next
)
199 if( ((nh
->flags
& SYM_INVALID
) != 0) && strcmp(name
, nh
->name
) == 0 )
202 DEBUG_Printf(DBG_CHN_MESG
, "Changing address for symbol %s (%08lx:%08lx => %08lx:%08lx)\n",
203 name
, nh
->value
.addr
.seg
, nh
->value
.addr
.off
, value
->addr
.seg
, value
->addr
.off
);
205 nh
->value
.addr
= value
->addr
;
206 if( nh
->value
.type
== NULL
&& value
->type
!= NULL
)
208 nh
->value
.type
= value
->type
;
209 nh
->value
.cookie
= value
->cookie
;
211 /* it may happen that the same symbol is defined in several compilation
212 * units, but the linker decides to merge it into a single instance.
213 * in that case, we don't clear the invalid flag for all the compilation
214 * units (N_GSYM), and wait to get the symbol from the symtab
216 if ((flags
& SYM_INVALID
) == 0)
217 nh
->flags
&= ~SYM_INVALID
;
221 if (nh
->value
.addr
.seg
== value
->addr
.seg
&&
222 nh
->value
.addr
.off
== value
->addr
.off
&&
223 strcmp(name
, nh
->name
) == 0 )
230 DEBUG_Printf(DBG_CHN_TRACE
, "adding symbol (%s) from file '%s' at 0x%04lx:%08lx\n",
231 name
, source
, value
->addr
.seg
, value
->addr
.off
);
235 * First see if we already have an entry for this symbol. If so
236 * return it, so we don't end up with duplicates.
239 new = (struct name_hash
*) DBG_alloc(sizeof(struct name_hash
));
241 new->name
= DBG_strdup(name
);
246 * This is an enhancement to reduce memory consumption. The idea
247 * is that we duplicate a given string only once. This is a big
248 * win if there are lots of symbols defined in a given source file.
250 if( strcmp(source
, prev_source
) == 0 )
252 new->sourcefile
= prev_duped_source
;
256 strcpy(prev_source
, source
);
257 prev_duped_source
= new->sourcefile
= DBG_strdup(source
);
262 new->sourcefile
= NULL
;
266 new->lines_alloc
= 0;
270 new->locals_alloc
= 0;
271 new->local_vars
= NULL
;
276 /* Now insert into the hash table */
277 new->next
= name_hash_table
[hash
];
278 name_hash_table
[hash
] = new;
281 * Check some heuristics based upon the file name to see whether
282 * we want to step through this guy or not. These are machine generated
283 * assembly files that are used to translate between the MS way of
284 * calling things and the GCC way of calling things. In general we
285 * always want to step through.
289 c
= strrchr(source
, '.');
290 if( c
!= NULL
&& strcmp(c
, ".s") == 0 )
292 c
= strrchr(source
, '/');
296 if( (strcmp(c
, "callfrom16.s") == 0)
297 || (strcmp(c
, "callto16.s") == 0)
298 || (strcmp(c
, "call32.s") == 0) )
300 new->flags
|= SYM_TRAMPOLINE
;
306 sortlist_valid
= FALSE
;
310 BOOL
DEBUG_Normalize(struct name_hash
* nh
)
314 * We aren't adding any more locals or linenumbers to this function.
315 * Free any spare memory that we might have allocated.
322 if( nh
->n_locals
!= nh
->locals_alloc
)
324 nh
->locals_alloc
= nh
->n_locals
;
325 nh
->local_vars
= DBG_realloc(nh
->local_vars
,
326 nh
->locals_alloc
* sizeof(WineLocals
));
329 if( nh
->n_lines
!= nh
->lines_alloc
)
331 nh
->lines_alloc
= nh
->n_lines
;
332 nh
->linetab
= DBG_realloc(nh
->linetab
,
333 nh
->lines_alloc
* sizeof(WineLineNo
));
339 /***********************************************************************
340 * DEBUG_GetSymbolValue
342 * Get the address of a named symbol.
344 BOOL
DEBUG_GetSymbolValue( const char * name
, const int lineno
,
345 DBG_VALUE
*value
, int bp_flag
)
347 struct name_hash
*nh
;
349 for(nh
= name_hash_table
[name_hash(name
)]; nh
; nh
= nh
->next
)
351 if( (nh
->flags
& SYM_INVALID
) != 0 )
356 if (!strcmp(nh
->name
, name
)) break;
359 if (!nh
&& (name
[0] != '_'))
363 assert(strlen(name
) < sizeof(buffer
) - 2); /* one for '_', one for '\0' */
365 strcpy(buffer
+1, name
);
366 for(nh
= name_hash_table
[name_hash(buffer
)]; nh
; nh
= nh
->next
)
368 if( (nh
->flags
& SYM_INVALID
) != 0 )
372 if (!strcmp(nh
->name
, buffer
)) break;
377 * If we don't have anything here, then try and see if this
378 * is a local symbol to the current stack frame. No matter
379 * what, we have nothing more to do, so we let that function
380 * decide what we ultimately return.
384 return DEBUG_GetStackSymbolValue(name
, value
);
387 value
->type
= nh
->value
.type
;
388 value
->cookie
= nh
->value
.cookie
;
389 return DEBUG_GetLineNumberAddr( nh
, lineno
, &value
->addr
, bp_flag
);
392 /***********************************************************************
393 * DEBUG_GetLineNumberAddr
395 * Get the address of a named symbol.
397 BOOL
DEBUG_GetLineNumberAddr( const struct name_hash
* nh
, const int lineno
,
398 DBG_ADDR
*addr
, int bp_flag
)
404 *addr
= nh
->value
.addr
;
407 addr
->off
+= nh
->breakpoint_offset
;
413 * Search for the specific line number. If we don't find it,
416 if( nh
->linetab
== NULL
)
421 for(i
=0; i
< nh
->n_lines
; i
++ )
423 if( nh
->linetab
[i
].line_number
== lineno
)
425 *addr
= nh
->linetab
[i
].pc_offset
;
431 * This specific line number not found.
440 /***********************************************************************
441 * DEBUG_SetSymbolValue
443 * Set the address of a named symbol.
445 BOOL
DEBUG_SetSymbolValue( const char * name
, const DBG_VALUE
*value
)
448 struct name_hash
*nh
;
450 assert(value
->cookie
== DV_TARGET
|| value
->cookie
== DV_HOST
);
452 for(nh
= name_hash_table
[name_hash(name
)]; nh
; nh
= nh
->next
)
453 if (!strcmp(nh
->name
, name
)) break;
455 if (!nh
&& (name
[0] != '_'))
458 strcpy(buffer
+1, name
);
459 for(nh
= name_hash_table
[name_hash(buffer
)]; nh
; nh
= nh
->next
)
460 if (!strcmp(nh
->name
, buffer
)) break;
463 if (!nh
) return FALSE
;
465 nh
->flags
&= ~SYM_INVALID
;
468 DEBUG_FixAddress( &nh
->value
.addr
, DEBUG_context
.SegDs
);
475 /***********************************************************************
476 * DEBUG_FindNearestSymbol
478 * Find the symbol nearest to a given address.
479 * If ebp is specified as non-zero, it means we should dump the argument
480 * list into the string we return as well.
482 const char * DEBUG_FindNearestSymbol( const DBG_ADDR
*addr
, int flag
,
483 struct name_hash
** rtn
,
485 struct list_id
* source
)
487 static char name_buffer
[MAX_PATH
+ 256];
488 static char arglist
[1024];
489 static char argtmp
[256];
490 struct name_hash
* nearest
= NULL
;
494 char * lineinfo
, *sourcefile
;
506 source
->sourcefile
= NULL
;
510 if( sortlist_valid
== FALSE
)
512 DEBUG_ResortSymbols();
515 if( sortlist_valid
== FALSE
)
521 * FIXME - use the binary search that we added to
522 * the function DEBUG_CheckLinenoStatus. Better yet, we should
523 * probably keep some notion of the current function so we don't
524 * have to search every time.
527 * Binary search to find closest symbol.
531 if( addr_sorttab
[0]->value
.addr
.seg
> addr
->seg
532 || ( addr_sorttab
[0]->value
.addr
.seg
== addr
->seg
533 && addr_sorttab
[0]->value
.addr
.off
> addr
->off
) )
537 else if( addr_sorttab
[high
- 1]->value
.addr
.seg
< addr
->seg
538 || ( addr_sorttab
[high
- 1]->value
.addr
.seg
== addr
->seg
539 && addr_sorttab
[high
- 1]->value
.addr
.off
< addr
->off
) )
541 nearest
= addr_sorttab
[high
- 1];
547 mid
= (high
+ low
)/2;
551 * See if there are any other entries that might also
552 * have the same address, and would also have a line
555 if( mid
> 0 && addr_sorttab
[mid
]->linetab
== NULL
)
557 if( (addr_sorttab
[mid
- 1]->value
.addr
.seg
==
558 addr_sorttab
[mid
]->value
.addr
.seg
)
559 && (addr_sorttab
[mid
- 1]->value
.addr
.off
==
560 addr_sorttab
[mid
]->value
.addr
.off
)
561 && (addr_sorttab
[mid
- 1]->linetab
!= NULL
) )
567 if( (mid
< sorttab_nsym
- 1)
568 && (addr_sorttab
[mid
]->linetab
== NULL
) )
570 if( (addr_sorttab
[mid
+ 1]->value
.addr
.seg
==
571 addr_sorttab
[mid
]->value
.addr
.seg
)
572 && (addr_sorttab
[mid
+ 1]->value
.addr
.off
==
573 addr_sorttab
[mid
]->value
.addr
.off
)
574 && (addr_sorttab
[mid
+ 1]->linetab
!= NULL
) )
579 nearest
= addr_sorttab
[mid
];
581 DEBUG_Printf(DBG_CHN_MESG
, "Found %x:%x when looking for %x:%x %x %s\n",
582 addr_sorttab
[mid
]->value
.addr
.seg
,
583 addr_sorttab
[mid
]->value
.addr
.off
,
584 addr
->seg
, addr
->off
,
585 addr_sorttab
[mid
]->linetab
,
586 addr_sorttab
[mid
]->name
);
590 if( (addr_sorttab
[mid
]->value
.addr
.seg
< addr
->seg
)
591 || ( addr_sorttab
[mid
]->value
.addr
.seg
== addr
->seg
592 && addr_sorttab
[mid
]->value
.addr
.off
<= addr
->off
) )
603 if (!nearest
) return NULL
;
611 * Fill in the relevant bits to the structure so that we can
612 * locate the source and line for this bit of code.
616 source
->sourcefile
= nearest
->sourcefile
;
617 if( nearest
->linetab
== NULL
)
623 source
->line
= nearest
->linetab
[0].line_number
;
631 * Prepare to display the argument list. If ebp is specified, it is
632 * the framepointer for the function in question. If not specified,
633 * we don't want the arglist.
635 memset(arglist
, '\0', sizeof(arglist
));
638 for(i
=0; i
< nearest
->n_locals
; i
++ )
641 * If this is a register (offset == 0) or a local
642 * variable, we don't want to know about it.
644 if( nearest
->local_vars
[i
].offset
<= 0 )
649 ptr
= (unsigned int *) (ebp
+ nearest
->local_vars
[i
].offset
);
650 if( arglist
[0] == '\0' )
656 strcat(arglist
, ", ");
658 DEBUG_READ_MEM_VERBOSE(ptr
, &val
, sizeof(val
));
659 sprintf(argtmp
, "%s=0x%x", nearest
->local_vars
[i
].name
, val
);
661 strcat(arglist
, argtmp
);
663 if( arglist
[0] == '(' )
665 strcat(arglist
, ")");
669 if( (nearest
->sourcefile
!= NULL
) && (flag
== TRUE
)
670 && (addr
->off
- nearest
->value
.addr
.off
< 0x100000) )
674 * Try and find the nearest line number to the current offset.
676 if( nearest
->linetab
!= NULL
)
679 high
= nearest
->n_lines
;
680 while ((high
- low
) > 1)
682 mid
= (high
+ low
) / 2;
683 if (addr
->off
< nearest
->linetab
[mid
].pc_offset
.off
)
688 lineno
= nearest
->linetab
[low
].line_number
;
693 sprintf(linebuff
, ":%d", lineno
);
697 source
->line
= lineno
;
701 /* Remove the path from the file name */
702 sourcefile
= strrchr( nearest
->sourcefile
, '/' );
703 if (!sourcefile
) sourcefile
= nearest
->sourcefile
;
706 if (addr
->off
== nearest
->value
.addr
.off
)
707 sprintf( name_buffer
, "%s%s [%s%s]", nearest
->name
,
708 arglist
, sourcefile
, lineinfo
);
710 sprintf( name_buffer
, "%s+0x%lx%s [%s%s]", nearest
->name
,
711 addr
->off
- nearest
->value
.addr
.off
,
712 arglist
, sourcefile
, lineinfo
);
716 if (addr
->off
== nearest
->value
.addr
.off
)
717 sprintf( name_buffer
, "%s%s", nearest
->name
, arglist
);
719 if (addr
->seg
&& (nearest
->value
.addr
.seg
!=addr
->seg
))
722 sprintf( name_buffer
, "%s+0x%lx%s", nearest
->name
,
723 addr
->off
- nearest
->value
.addr
.off
, arglist
);
730 /***********************************************************************
731 * DEBUG_ReadSymbolTable
733 * Read a symbol file into the hash table.
735 void DEBUG_ReadSymbolTable( const char * filename
)
744 if (!(symbolfile
= fopen(filename
, "r")))
746 DEBUG_Printf( DBG_CHN_WARN
, "Unable to open symbol table %s\n", filename
);
750 DEBUG_Printf( DBG_CHN_MESG
, "Reading symbols from file %s\n", filename
);
755 value
.cookie
= DV_TARGET
;
759 fgets( buffer
, sizeof(buffer
), symbolfile
);
760 if (feof(symbolfile
)) break;
762 /* Strip any text after a # sign (i.e. comments) */
765 if(*cpnt
++ == '#') { *cpnt
= 0; break; }
767 /* Quietly ignore any lines that have just whitespace */
771 if(*cpnt
!= ' ' && *cpnt
!= '\t') break;
774 if (!(*cpnt
) || *cpnt
== '\n') continue;
776 if (sscanf(buffer
, "%lx %c %s", &value
.addr
.off
, &type
, name
) == 3)
777 DEBUG_AddSymbol( name
, &value
, NULL
, SYM_WINE
);
784 DEBUG_AddLineNumber( struct name_hash
* func
, int line_num
,
785 unsigned long offset
)
792 if( func
->n_lines
+ 1 >= func
->lines_alloc
)
794 func
->lines_alloc
+= 64;
795 func
->linetab
= DBG_realloc(func
->linetab
,
796 func
->lines_alloc
* sizeof(WineLineNo
));
799 func
->linetab
[func
->n_lines
].line_number
= line_num
;
800 func
->linetab
[func
->n_lines
].pc_offset
.seg
= func
->value
.addr
.seg
;
801 func
->linetab
[func
->n_lines
].pc_offset
.off
= func
->value
.addr
.off
+ offset
;
807 DEBUG_AddLocal( struct name_hash
* func
, int regno
,
818 if( func
->n_locals
+ 1 >= func
->locals_alloc
)
820 func
->locals_alloc
+= 32;
821 func
->local_vars
= DBG_realloc(func
->local_vars
,
822 func
->locals_alloc
* sizeof(WineLocals
));
825 func
->local_vars
[func
->n_locals
].regno
= regno
;
826 func
->local_vars
[func
->n_locals
].offset
= offset
;
827 func
->local_vars
[func
->n_locals
].pc_start
= pc_start
;
828 func
->local_vars
[func
->n_locals
].pc_end
= pc_end
;
829 func
->local_vars
[func
->n_locals
].name
= DBG_strdup(name
);
830 func
->local_vars
[func
->n_locals
].type
= NULL
;
833 return &func
->local_vars
[func
->n_locals
- 1];
837 DEBUG_DumpHashInfo(void)
841 struct name_hash
*nh
;
844 * Utility function to dump stats about the hash table.
846 for(i
=0; i
<NR_NAME_HASH
; i
++)
849 for (nh
= name_hash_table
[i
]; nh
; nh
= nh
->next
)
853 DEBUG_Printf(DBG_CHN_MESG
, "Bucket %d: %d\n", i
, depth
);
857 /***********************************************************************
858 * DEBUG_CheckLinenoStatus
860 * Find the symbol nearest to a given address.
861 * If ebp is specified as non-zero, it means we should dump the argument
862 * list into the string we return as well.
864 int DEBUG_CheckLinenoStatus( const DBG_ADDR
*addr
)
866 struct name_hash
* nearest
= NULL
;
869 if( sortlist_valid
== FALSE
)
871 DEBUG_ResortSymbols();
875 * Binary search to find closest symbol.
879 if( addr_sorttab
[0]->value
.addr
.seg
> addr
->seg
880 || ( addr_sorttab
[0]->value
.addr
.seg
== addr
->seg
881 && addr_sorttab
[0]->value
.addr
.off
> addr
->off
) )
885 else if( addr_sorttab
[high
- 1]->value
.addr
.seg
< addr
->seg
886 || ( addr_sorttab
[high
- 1]->value
.addr
.seg
== addr
->seg
887 && addr_sorttab
[high
- 1]->value
.addr
.off
< addr
->off
) )
889 nearest
= addr_sorttab
[high
- 1];
895 mid
= (high
+ low
)/2;
899 * See if there are any other entries that might also
900 * have the same address, and would also have a line
903 if( mid
> 0 && addr_sorttab
[mid
]->linetab
== NULL
)
905 if( (addr_sorttab
[mid
- 1]->value
.addr
.seg
==
906 addr_sorttab
[mid
]->value
.addr
.seg
)
907 && (addr_sorttab
[mid
- 1]->value
.addr
.off
==
908 addr_sorttab
[mid
]->value
.addr
.off
)
909 && (addr_sorttab
[mid
- 1]->linetab
!= NULL
) )
915 if( (mid
< sorttab_nsym
- 1)
916 && (addr_sorttab
[mid
]->linetab
== NULL
) )
918 if( (addr_sorttab
[mid
+ 1]->value
.addr
.seg
==
919 addr_sorttab
[mid
]->value
.addr
.seg
)
920 && (addr_sorttab
[mid
+ 1]->value
.addr
.off
==
921 addr_sorttab
[mid
]->value
.addr
.off
)
922 && (addr_sorttab
[mid
+ 1]->linetab
!= NULL
) )
927 nearest
= addr_sorttab
[mid
];
929 DEBUG_Printf(DBG_CHN_MESG
, "Found %x:%x when looking for %x:%x %x %s\n",
930 addr_sorttab
[mid
]->value
.addr
.seg
,
931 addr_sorttab
[mid
]->value
.addr
.off
,
932 addr
->seg
, addr
->off
,
933 addr_sorttab
[mid
]->linetab
,
934 addr_sorttab
[mid
]->name
);
938 if( (addr_sorttab
[mid
]->value
.addr
.seg
< addr
->seg
)
939 || ( addr_sorttab
[mid
]->value
.addr
.seg
== addr
->seg
940 && addr_sorttab
[mid
]->value
.addr
.off
<= addr
->off
) )
951 if (!nearest
) return FUNC_HAS_NO_LINES
;
953 if( nearest
->flags
& SYM_STEP_THROUGH
)
956 * This will cause us to keep single stepping until
957 * we get to the other side somewhere.
959 return NOT_ON_LINENUMBER
;
962 if( (nearest
->flags
& SYM_TRAMPOLINE
) )
965 * This will cause us to keep single stepping until
966 * we get to the other side somewhere.
968 return FUNC_IS_TRAMPOLINE
;
971 if( nearest
->linetab
== NULL
)
973 return FUNC_HAS_NO_LINES
;
978 * We never want to stop on the first instruction of a function
979 * even if it has it's own linenumber. Let the thing keep running
980 * until it gets past the function prologue. We only do this if there
981 * is more than one line number for the function, of course.
983 if( nearest
->value
.addr
.off
== addr
->off
&& nearest
->n_lines
> 1 )
985 return NOT_ON_LINENUMBER
;
988 if( (nearest
->sourcefile
!= NULL
)
989 && (addr
->off
- nearest
->value
.addr
.off
< 0x100000) )
992 high
= nearest
->n_lines
;
993 while ((high
- low
) > 1)
995 mid
= (high
+ low
) / 2;
996 if (addr
->off
< nearest
->linetab
[mid
].pc_offset
.off
) high
= mid
;
999 if (addr
->off
== nearest
->linetab
[low
].pc_offset
.off
)
1000 return AT_LINENUMBER
;
1002 return NOT_ON_LINENUMBER
;
1005 return FUNC_HAS_NO_LINES
;
1008 /***********************************************************************
1011 * Find the symbol nearest to a given address.
1012 * Returns sourcefile name and line number in a format that the listing
1013 * handler can deal with.
1016 DEBUG_GetFuncInfo( struct list_id
* ret
, const char * filename
,
1021 struct name_hash
*nh
;
1023 for(nh
= name_hash_table
[name_hash(name
)]; nh
; nh
= nh
->next
)
1025 if( filename
!= NULL
)
1028 if( nh
->sourcefile
== NULL
)
1033 pnt
= strrchr(nh
->sourcefile
, '/');
1034 if( strcmp(nh
->sourcefile
, filename
) != 0
1035 && (pnt
== NULL
|| strcmp(pnt
+ 1, filename
) != 0) )
1040 if (!strcmp(nh
->name
, name
)) break;
1043 if (!nh
&& (name
[0] != '_'))
1046 strcpy(buffer
+1, name
);
1047 for(nh
= name_hash_table
[name_hash(buffer
)]; nh
; nh
= nh
->next
)
1049 if( filename
!= NULL
)
1051 if( nh
->sourcefile
== NULL
)
1056 pnt
= strrchr(nh
->sourcefile
, '/');
1057 if( strcmp(nh
->sourcefile
, filename
) != 0
1058 && (pnt
== NULL
|| strcmp(pnt
+ 1, filename
) != 0) )
1063 if (!strcmp(nh
->name
, buffer
)) break;
1069 if( filename
!= NULL
)
1071 DEBUG_Printf(DBG_CHN_MESG
, "No such function %s in %s\n", name
, filename
);
1075 DEBUG_Printf(DBG_CHN_MESG
, "No such function %s\n", name
);
1077 ret
->sourcefile
= NULL
;
1082 ret
->sourcefile
= nh
->sourcefile
;
1085 * Search for the specific line number. If we don't find it,
1086 * then return FALSE.
1088 if( nh
->linetab
== NULL
)
1094 ret
->line
= nh
->linetab
[0].line_number
;
1098 /***********************************************************************
1099 * DEBUG_GetStackSymbolValue
1101 * Get the address of a named symbol from the current stack frame.
1104 BOOL
DEBUG_GetStackSymbolValue( const char * name
, DBG_VALUE
*value
)
1106 struct name_hash
* curr_func
;
1111 if( DEBUG_GetCurrentFrame(&curr_func
, &eip
, &ebp
) == FALSE
)
1116 for(i
=0; i
< curr_func
->n_locals
; i
++ )
1119 * Test the range of validity of the local variable. This
1120 * comes up with RBRAC/LBRAC stabs in particular.
1122 if( (curr_func
->local_vars
[i
].pc_start
!= 0)
1123 && ((eip
- curr_func
->value
.addr
.off
)
1124 < curr_func
->local_vars
[i
].pc_start
) )
1129 if( (curr_func
->local_vars
[i
].pc_end
!= 0)
1130 && ((eip
- curr_func
->value
.addr
.off
)
1131 > curr_func
->local_vars
[i
].pc_end
) )
1136 if( strcmp(name
, curr_func
->local_vars
[i
].name
) == 0 )
1139 * OK, we found it. Now figure out what to do with this.
1141 if( curr_func
->local_vars
[i
].regno
!= 0 )
1144 * Register variable. Point to DEBUG_context field.
1146 assert(curr_func
->local_vars
[i
].regno
- 1 < sizeof(reg_ofs
)/sizeof(reg_ofs
[0]));
1147 value
->addr
.off
= ((DWORD
)&DEBUG_context
) +
1148 reg_ofs
[curr_func
->local_vars
[i
].regno
- 1];
1149 value
->cookie
= DV_HOST
;
1153 value
->addr
.off
= ebp
+ curr_func
->local_vars
[i
].offset
;
1154 value
->cookie
= DV_TARGET
;
1156 value
->addr
.seg
= 0;
1157 value
->type
= curr_func
->local_vars
[i
].type
;
1167 DEBUG_InfoLocals(void)
1169 struct name_hash
* curr_func
;
1176 if( DEBUG_GetCurrentFrame(&curr_func
, &eip
, &ebp
) == FALSE
)
1181 for(i
=0; i
< curr_func
->n_locals
; i
++ )
1184 * Test the range of validity of the local variable. This
1185 * comes up with RBRAC/LBRAC stabs in particular.
1187 if( (curr_func
->local_vars
[i
].pc_start
!= 0)
1188 && ((eip
- curr_func
->value
.addr
.off
)
1189 < curr_func
->local_vars
[i
].pc_start
) )
1194 if( (curr_func
->local_vars
[i
].pc_end
!= 0)
1195 && ((eip
- curr_func
->value
.addr
.off
)
1196 > curr_func
->local_vars
[i
].pc_end
) )
1201 if( curr_func
->local_vars
[i
].regno
!= 0 )
1203 ptr
= (unsigned int *)(((DWORD
)&DEBUG_context
)
1204 + reg_ofs
[curr_func
->local_vars
[i
].regno
- 1]);
1205 DEBUG_Printf(DBG_CHN_MESG
, "%s:%s (optimized into register $%s) == 0x%8.8x\n",
1206 curr_func
->name
, curr_func
->local_vars
[i
].name
,
1207 reg_name
[curr_func
->local_vars
[i
].regno
- 1],
1212 DEBUG_READ_MEM_VERBOSE((void*)(ebp
+ curr_func
->local_vars
[i
].offset
),
1214 DEBUG_Printf(DBG_CHN_MESG
, "%s:%s == 0x%8.8x\n",
1215 curr_func
->name
, curr_func
->local_vars
[i
].name
, val
);
1223 DEBUG_SetSymbolSize(struct name_hash
* sym
, unsigned int len
)
1225 sym
->symbol_size
= len
;
1231 DEBUG_SetSymbolBPOff(struct name_hash
* sym
, unsigned int off
)
1233 sym
->breakpoint_offset
= off
;
1239 DEBUG_GetSymbolAddr(struct name_hash
* sym
, DBG_ADDR
* addr
)
1242 *addr
= sym
->value
.addr
;
1247 int DEBUG_SetLocalSymbolType(struct wine_locals
* sym
, struct datatype
* type
)