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
;
207 if( nh
->value
.type
== NULL
&& value
->type
!= NULL
)
209 nh
->value
.type
= value
->type
;
210 nh
->value
.cookie
= value
->cookie
;
212 /* it may happen that the same symbol is defined in several compilation
213 * units, but the linker decides to merge it into a single instance.
214 * in that case, we don't clear the invalid flag for all the compilation
215 * units (N_GSYM), and wait to get the symbol from the symtab
217 if ((flags
& SYM_INVALID
) == 0)
218 nh
->flags
&= ~SYM_INVALID
;
222 if (nh
->value
.addr
.seg
== value
->addr
.seg
&&
223 nh
->value
.addr
.off
== value
->addr
.off
&&
224 strcmp(name
, nh
->name
) == 0 )
231 DEBUG_Printf(DBG_CHN_TRACE
, "adding symbol (%s) from file '%s' at 0x%04lx:%08lx\n",
232 name
, source
, value
->addr
.seg
, value
->addr
.off
);
236 * First see if we already have an entry for this symbol. If so
237 * return it, so we don't end up with duplicates.
240 new = (struct name_hash
*) DBG_alloc(sizeof(struct name_hash
));
242 new->name
= DBG_strdup(name
);
247 * This is an enhancement to reduce memory consumption. The idea
248 * is that we duplicate a given string only once. This is a big
249 * win if there are lots of symbols defined in a given source file.
251 if( strcmp(source
, prev_source
) == 0 )
253 new->sourcefile
= prev_duped_source
;
257 strcpy(prev_source
, source
);
258 prev_duped_source
= new->sourcefile
= DBG_strdup(source
);
263 new->sourcefile
= NULL
;
267 new->lines_alloc
= 0;
271 new->locals_alloc
= 0;
272 new->local_vars
= NULL
;
277 /* Now insert into the hash table */
278 new->next
= name_hash_table
[hash
];
279 name_hash_table
[hash
] = new;
282 * Check some heuristics based upon the file name to see whether
283 * we want to step through this guy or not. These are machine generated
284 * assembly files that are used to translate between the MS way of
285 * calling things and the GCC way of calling things. In general we
286 * always want to step through.
290 c
= strrchr(source
, '.');
291 if( c
!= NULL
&& strcmp(c
, ".s") == 0 )
293 c
= strrchr(source
, '/');
297 if( (strcmp(c
, "callfrom16.s") == 0)
298 || (strcmp(c
, "callto16.s") == 0)
299 || (strcmp(c
, "call32.s") == 0) )
301 new->flags
|= SYM_TRAMPOLINE
;
307 sortlist_valid
= FALSE
;
311 BOOL
DEBUG_Normalize(struct name_hash
* nh
)
315 * We aren't adding any more locals or linenumbers to this function.
316 * Free any spare memory that we might have allocated.
323 if( nh
->n_locals
!= nh
->locals_alloc
)
325 nh
->locals_alloc
= nh
->n_locals
;
326 nh
->local_vars
= DBG_realloc(nh
->local_vars
,
327 nh
->locals_alloc
* sizeof(WineLocals
));
330 if( nh
->n_lines
!= nh
->lines_alloc
)
332 nh
->lines_alloc
= nh
->n_lines
;
333 nh
->linetab
= DBG_realloc(nh
->linetab
,
334 nh
->lines_alloc
* sizeof(WineLineNo
));
340 /***********************************************************************
341 * DEBUG_GetSymbolValue
343 * Get the address of a named symbol.
345 BOOL
DEBUG_GetSymbolValue( const char * name
, const int lineno
,
346 DBG_VALUE
*value
, int bp_flag
)
349 struct name_hash
*nh
;
351 for(nh
= name_hash_table
[name_hash(name
)]; nh
; nh
= nh
->next
)
353 if( (nh
->flags
& SYM_INVALID
) != 0 )
358 if (!strcmp(nh
->name
, name
)) break;
361 if (!nh
&& (name
[0] != '_'))
364 strcpy(buffer
+1, name
);
365 for(nh
= name_hash_table
[name_hash(buffer
)]; nh
; nh
= nh
->next
)
367 if( (nh
->flags
& SYM_INVALID
) != 0 )
371 if (!strcmp(nh
->name
, buffer
)) break;
376 * If we don't have anything here, then try and see if this
377 * is a local symbol to the current stack frame. No matter
378 * what, we have nothing more to do, so we let that function
379 * decide what we ultimately return.
383 return DEBUG_GetStackSymbolValue(name
, value
);
386 value
->type
= nh
->value
.type
;
387 value
->cookie
= nh
->value
.cookie
;
388 return DEBUG_GetLineNumberAddr( nh
, lineno
, &value
->addr
, bp_flag
);
391 /***********************************************************************
392 * DEBUG_GetLineNumberAddr
394 * Get the address of a named symbol.
396 BOOL
DEBUG_GetLineNumberAddr( struct name_hash
* nh
, const int lineno
,
397 DBG_ADDR
*addr
, int bp_flag
)
403 *addr
= nh
->value
.addr
;
406 addr
->off
+= nh
->breakpoint_offset
;
412 * Search for the specific line number. If we don't find it,
415 if( nh
->linetab
== NULL
)
420 for(i
=0; i
< nh
->n_lines
; i
++ )
422 if( nh
->linetab
[i
].line_number
== lineno
)
424 *addr
= nh
->linetab
[i
].pc_offset
;
430 * This specific line number not found.
439 /***********************************************************************
440 * DEBUG_SetSymbolValue
442 * Set the address of a named symbol.
444 BOOL
DEBUG_SetSymbolValue( const char * name
, const DBG_VALUE
*value
)
447 struct name_hash
*nh
;
449 assert(value
->cookie
== DV_TARGET
|| value
->cookie
== DV_HOST
);
451 for(nh
= name_hash_table
[name_hash(name
)]; nh
; nh
= nh
->next
)
452 if (!strcmp(nh
->name
, name
)) break;
454 if (!nh
&& (name
[0] != '_'))
457 strcpy(buffer
+1, name
);
458 for(nh
= name_hash_table
[name_hash(buffer
)]; nh
; nh
= nh
->next
)
459 if (!strcmp(nh
->name
, buffer
)) break;
462 if (!nh
) return FALSE
;
464 nh
->flags
&= ~SYM_INVALID
;
465 DEBUG_FixAddress( &nh
->value
.addr
, DEBUG_context
.SegDs
);
470 /***********************************************************************
471 * DEBUG_FindNearestSymbol
473 * Find the symbol nearest to a given address.
474 * If ebp is specified as non-zero, it means we should dump the argument
475 * list into the string we return as well.
477 const char * DEBUG_FindNearestSymbol( const DBG_ADDR
*addr
, int flag
,
478 struct name_hash
** rtn
,
480 struct list_id
* source
)
482 static char name_buffer
[MAX_PATH
+ 256];
483 static char arglist
[1024];
484 static char argtmp
[256];
485 struct name_hash
* nearest
= NULL
;
489 char * lineinfo
, *sourcefile
;
501 source
->sourcefile
= NULL
;
505 if( sortlist_valid
== FALSE
)
507 DEBUG_ResortSymbols();
510 if( sortlist_valid
== FALSE
)
516 * FIXME - use the binary search that we added to
517 * the function DEBUG_CheckLinenoStatus. Better yet, we should
518 * probably keep some notion of the current function so we don't
519 * have to search every time.
522 * Binary search to find closest symbol.
526 if( addr_sorttab
[0]->value
.addr
.seg
> addr
->seg
527 || ( addr_sorttab
[0]->value
.addr
.seg
== addr
->seg
528 && addr_sorttab
[0]->value
.addr
.off
> addr
->off
) )
532 else if( addr_sorttab
[high
- 1]->value
.addr
.seg
< addr
->seg
533 || ( addr_sorttab
[high
- 1]->value
.addr
.seg
== addr
->seg
534 && addr_sorttab
[high
- 1]->value
.addr
.off
< addr
->off
) )
536 nearest
= addr_sorttab
[high
- 1];
542 mid
= (high
+ low
)/2;
546 * See if there are any other entries that might also
547 * have the same address, and would also have a line
550 if( mid
> 0 && addr_sorttab
[mid
]->linetab
== NULL
)
552 if( (addr_sorttab
[mid
- 1]->value
.addr
.seg
==
553 addr_sorttab
[mid
]->value
.addr
.seg
)
554 && (addr_sorttab
[mid
- 1]->value
.addr
.off
==
555 addr_sorttab
[mid
]->value
.addr
.off
)
556 && (addr_sorttab
[mid
- 1]->linetab
!= NULL
) )
562 if( (mid
< sorttab_nsym
- 1)
563 && (addr_sorttab
[mid
]->linetab
== NULL
) )
565 if( (addr_sorttab
[mid
+ 1]->value
.addr
.seg
==
566 addr_sorttab
[mid
]->value
.addr
.seg
)
567 && (addr_sorttab
[mid
+ 1]->value
.addr
.off
==
568 addr_sorttab
[mid
]->value
.addr
.off
)
569 && (addr_sorttab
[mid
+ 1]->linetab
!= NULL
) )
574 nearest
= addr_sorttab
[mid
];
576 DEBUG_Printf(DBG_CHN_MESG
, "Found %x:%x when looking for %x:%x %x %s\n",
577 addr_sorttab
[mid
]->value
.addr
.seg
,
578 addr_sorttab
[mid
]->value
.addr
.off
,
579 addr
->seg
, addr
->off
,
580 addr_sorttab
[mid
]->linetab
,
581 addr_sorttab
[mid
]->name
);
585 if( (addr_sorttab
[mid
]->value
.addr
.seg
< addr
->seg
)
586 || ( addr_sorttab
[mid
]->value
.addr
.seg
== addr
->seg
587 && addr_sorttab
[mid
]->value
.addr
.off
<= addr
->off
) )
598 if (!nearest
) return NULL
;
606 * Fill in the relevant bits to the structure so that we can
607 * locate the source and line for this bit of code.
611 source
->sourcefile
= nearest
->sourcefile
;
612 if( nearest
->linetab
== NULL
)
618 source
->line
= nearest
->linetab
[0].line_number
;
626 * Prepare to display the argument list. If ebp is specified, it is
627 * the framepointer for the function in question. If not specified,
628 * we don't want the arglist.
630 memset(arglist
, '\0', sizeof(arglist
));
633 for(i
=0; i
< nearest
->n_locals
; i
++ )
636 * If this is a register (offset == 0) or a local
637 * variable, we don't want to know about it.
639 if( nearest
->local_vars
[i
].offset
<= 0 )
644 ptr
= (unsigned int *) (ebp
+ nearest
->local_vars
[i
].offset
);
645 if( arglist
[0] == '\0' )
651 strcat(arglist
, ", ");
653 DEBUG_READ_MEM_VERBOSE(ptr
, &val
, sizeof(val
));
654 sprintf(argtmp
, "%s=0x%x", nearest
->local_vars
[i
].name
, val
);
656 strcat(arglist
, argtmp
);
658 if( arglist
[0] == '(' )
660 strcat(arglist
, ")");
664 if( (nearest
->sourcefile
!= NULL
) && (flag
== TRUE
)
665 && (addr
->off
- nearest
->value
.addr
.off
< 0x100000) )
669 * Try and find the nearest line number to the current offset.
671 if( nearest
->linetab
!= NULL
)
674 high
= nearest
->n_lines
;
675 while ((high
- low
) > 1)
677 mid
= (high
+ low
) / 2;
678 if (addr
->off
< nearest
->linetab
[mid
].pc_offset
.off
)
683 lineno
= nearest
->linetab
[low
].line_number
;
688 sprintf(linebuff
, ":%d", lineno
);
692 source
->line
= lineno
;
696 /* Remove the path from the file name */
697 sourcefile
= strrchr( nearest
->sourcefile
, '/' );
698 if (!sourcefile
) sourcefile
= nearest
->sourcefile
;
701 if (addr
->off
== nearest
->value
.addr
.off
)
702 sprintf( name_buffer
, "%s%s [%s%s]", nearest
->name
,
703 arglist
, sourcefile
, lineinfo
);
705 sprintf( name_buffer
, "%s+0x%lx%s [%s%s]", nearest
->name
,
706 addr
->off
- nearest
->value
.addr
.off
,
707 arglist
, sourcefile
, lineinfo
);
711 if (addr
->off
== nearest
->value
.addr
.off
)
712 sprintf( name_buffer
, "%s%s", nearest
->name
, arglist
);
714 if (addr
->seg
&& (nearest
->value
.addr
.seg
!=addr
->seg
))
717 sprintf( name_buffer
, "%s+0x%lx%s", nearest
->name
,
718 addr
->off
- nearest
->value
.addr
.off
, arglist
);
725 /***********************************************************************
726 * DEBUG_ReadSymbolTable
728 * Read a symbol file into the hash table.
730 void DEBUG_ReadSymbolTable( const char * filename
)
739 if (!(symbolfile
= fopen(filename
, "r")))
741 DEBUG_Printf( DBG_CHN_WARN
, "Unable to open symbol table %s\n", filename
);
745 DEBUG_Printf( DBG_CHN_MESG
, "Reading symbols from file %s\n", filename
);
750 value
.cookie
= DV_TARGET
;
754 fgets( buffer
, sizeof(buffer
), symbolfile
);
755 if (feof(symbolfile
)) break;
757 /* Strip any text after a # sign (i.e. comments) */
760 if(*cpnt
++ == '#') { *cpnt
= 0; break; }
762 /* Quietly ignore any lines that have just whitespace */
766 if(*cpnt
!= ' ' && *cpnt
!= '\t') break;
769 if (!(*cpnt
) || *cpnt
== '\n') continue;
771 if (sscanf(buffer
, "%lx %c %s", &value
.addr
.off
, &type
, name
) == 3)
772 DEBUG_AddSymbol( name
, &value
, NULL
, SYM_WINE
);
779 DEBUG_AddLineNumber( struct name_hash
* func
, int line_num
,
780 unsigned long offset
)
787 if( func
->n_lines
+ 1 >= func
->lines_alloc
)
789 func
->lines_alloc
+= 64;
790 func
->linetab
= DBG_realloc(func
->linetab
,
791 func
->lines_alloc
* sizeof(WineLineNo
));
794 func
->linetab
[func
->n_lines
].line_number
= line_num
;
795 func
->linetab
[func
->n_lines
].pc_offset
.seg
= func
->value
.addr
.seg
;
796 func
->linetab
[func
->n_lines
].pc_offset
.off
= func
->value
.addr
.off
+ offset
;
802 DEBUG_AddLocal( struct name_hash
* func
, int regno
,
813 if( func
->n_locals
+ 1 >= func
->locals_alloc
)
815 func
->locals_alloc
+= 32;
816 func
->local_vars
= DBG_realloc(func
->local_vars
,
817 func
->locals_alloc
* sizeof(WineLocals
));
820 func
->local_vars
[func
->n_locals
].regno
= regno
;
821 func
->local_vars
[func
->n_locals
].offset
= offset
;
822 func
->local_vars
[func
->n_locals
].pc_start
= pc_start
;
823 func
->local_vars
[func
->n_locals
].pc_end
= pc_end
;
824 func
->local_vars
[func
->n_locals
].name
= DBG_strdup(name
);
825 func
->local_vars
[func
->n_locals
].type
= NULL
;
828 return &func
->local_vars
[func
->n_locals
- 1];
832 DEBUG_DumpHashInfo(void)
836 struct name_hash
*nh
;
839 * Utility function to dump stats about the hash table.
841 for(i
=0; i
<NR_NAME_HASH
; i
++)
844 for (nh
= name_hash_table
[i
]; nh
; nh
= nh
->next
)
848 DEBUG_Printf(DBG_CHN_MESG
, "Bucket %d: %d\n", i
, depth
);
852 /***********************************************************************
853 * DEBUG_CheckLinenoStatus
855 * Find the symbol nearest to a given address.
856 * If ebp is specified as non-zero, it means we should dump the argument
857 * list into the string we return as well.
859 int DEBUG_CheckLinenoStatus( const DBG_ADDR
*addr
)
861 struct name_hash
* nearest
= NULL
;
864 if( sortlist_valid
== FALSE
)
866 DEBUG_ResortSymbols();
870 * Binary search to find closest symbol.
874 if( addr_sorttab
[0]->value
.addr
.seg
> addr
->seg
875 || ( addr_sorttab
[0]->value
.addr
.seg
== addr
->seg
876 && addr_sorttab
[0]->value
.addr
.off
> addr
->off
) )
880 else if( addr_sorttab
[high
- 1]->value
.addr
.seg
< addr
->seg
881 || ( addr_sorttab
[high
- 1]->value
.addr
.seg
== addr
->seg
882 && addr_sorttab
[high
- 1]->value
.addr
.off
< addr
->off
) )
884 nearest
= addr_sorttab
[high
- 1];
890 mid
= (high
+ low
)/2;
894 * See if there are any other entries that might also
895 * have the same address, and would also have a line
898 if( mid
> 0 && addr_sorttab
[mid
]->linetab
== NULL
)
900 if( (addr_sorttab
[mid
- 1]->value
.addr
.seg
==
901 addr_sorttab
[mid
]->value
.addr
.seg
)
902 && (addr_sorttab
[mid
- 1]->value
.addr
.off
==
903 addr_sorttab
[mid
]->value
.addr
.off
)
904 && (addr_sorttab
[mid
- 1]->linetab
!= NULL
) )
910 if( (mid
< sorttab_nsym
- 1)
911 && (addr_sorttab
[mid
]->linetab
== NULL
) )
913 if( (addr_sorttab
[mid
+ 1]->value
.addr
.seg
==
914 addr_sorttab
[mid
]->value
.addr
.seg
)
915 && (addr_sorttab
[mid
+ 1]->value
.addr
.off
==
916 addr_sorttab
[mid
]->value
.addr
.off
)
917 && (addr_sorttab
[mid
+ 1]->linetab
!= NULL
) )
922 nearest
= addr_sorttab
[mid
];
924 DEBUG_Printf(DBG_CHN_MESG
, "Found %x:%x when looking for %x:%x %x %s\n",
925 addr_sorttab
[mid
]->value
.addr
.seg
,
926 addr_sorttab
[mid
]->value
.addr
.off
,
927 addr
->seg
, addr
->off
,
928 addr_sorttab
[mid
]->linetab
,
929 addr_sorttab
[mid
]->name
);
933 if( (addr_sorttab
[mid
]->value
.addr
.seg
< addr
->seg
)
934 || ( addr_sorttab
[mid
]->value
.addr
.seg
== addr
->seg
935 && addr_sorttab
[mid
]->value
.addr
.off
<= addr
->off
) )
946 if (!nearest
) return FUNC_HAS_NO_LINES
;
948 if( nearest
->flags
& SYM_STEP_THROUGH
)
951 * This will cause us to keep single stepping until
952 * we get to the other side somewhere.
954 return NOT_ON_LINENUMBER
;
957 if( (nearest
->flags
& SYM_TRAMPOLINE
) )
960 * This will cause us to keep single stepping until
961 * we get to the other side somewhere.
963 return FUNC_IS_TRAMPOLINE
;
966 if( nearest
->linetab
== NULL
)
968 return FUNC_HAS_NO_LINES
;
973 * We never want to stop on the first instruction of a function
974 * even if it has it's own linenumber. Let the thing keep running
975 * until it gets past the function prologue. We only do this if there
976 * is more than one line number for the function, of course.
978 if( nearest
->value
.addr
.off
== addr
->off
&& nearest
->n_lines
> 1 )
980 return NOT_ON_LINENUMBER
;
983 if( (nearest
->sourcefile
!= NULL
)
984 && (addr
->off
- nearest
->value
.addr
.off
< 0x100000) )
987 high
= nearest
->n_lines
;
988 while ((high
- low
) > 1)
990 mid
= (high
+ low
) / 2;
991 if (addr
->off
< nearest
->linetab
[mid
].pc_offset
.off
) high
= mid
;
994 if (addr
->off
== nearest
->linetab
[low
].pc_offset
.off
)
995 return AT_LINENUMBER
;
997 return NOT_ON_LINENUMBER
;
1000 return FUNC_HAS_NO_LINES
;
1003 /***********************************************************************
1006 * Find the symbol nearest to a given address.
1007 * Returns sourcefile name and line number in a format that the listing
1008 * handler can deal with.
1011 DEBUG_GetFuncInfo( struct list_id
* ret
, const char * filename
,
1016 struct name_hash
*nh
;
1018 for(nh
= name_hash_table
[name_hash(name
)]; nh
; nh
= nh
->next
)
1020 if( filename
!= NULL
)
1023 if( nh
->sourcefile
== NULL
)
1028 pnt
= strrchr(nh
->sourcefile
, '/');
1029 if( strcmp(nh
->sourcefile
, filename
) != 0
1030 && (pnt
== NULL
|| strcmp(pnt
+ 1, filename
) != 0) )
1035 if (!strcmp(nh
->name
, name
)) break;
1038 if (!nh
&& (name
[0] != '_'))
1041 strcpy(buffer
+1, name
);
1042 for(nh
= name_hash_table
[name_hash(buffer
)]; nh
; nh
= nh
->next
)
1044 if( filename
!= NULL
)
1046 if( nh
->sourcefile
== NULL
)
1051 pnt
= strrchr(nh
->sourcefile
, '/');
1052 if( strcmp(nh
->sourcefile
, filename
) != 0
1053 && (pnt
== NULL
|| strcmp(pnt
+ 1, filename
) != 0) )
1058 if (!strcmp(nh
->name
, buffer
)) break;
1064 if( filename
!= NULL
)
1066 DEBUG_Printf(DBG_CHN_MESG
, "No such function %s in %s\n", name
, filename
);
1070 DEBUG_Printf(DBG_CHN_MESG
, "No such function %s\n", name
);
1072 ret
->sourcefile
= NULL
;
1077 ret
->sourcefile
= nh
->sourcefile
;
1080 * Search for the specific line number. If we don't find it,
1081 * then return FALSE.
1083 if( nh
->linetab
== NULL
)
1089 ret
->line
= nh
->linetab
[0].line_number
;
1093 /***********************************************************************
1094 * DEBUG_GetStackSymbolValue
1096 * Get the address of a named symbol from the current stack frame.
1099 BOOL
DEBUG_GetStackSymbolValue( const char * name
, DBG_VALUE
*value
)
1101 struct name_hash
* curr_func
;
1106 if( DEBUG_GetCurrentFrame(&curr_func
, &eip
, &ebp
) == FALSE
)
1111 for(i
=0; i
< curr_func
->n_locals
; i
++ )
1114 * Test the range of validity of the local variable. This
1115 * comes up with RBRAC/LBRAC stabs in particular.
1117 if( (curr_func
->local_vars
[i
].pc_start
!= 0)
1118 && ((eip
- curr_func
->value
.addr
.off
)
1119 < curr_func
->local_vars
[i
].pc_start
) )
1124 if( (curr_func
->local_vars
[i
].pc_end
!= 0)
1125 && ((eip
- curr_func
->value
.addr
.off
)
1126 > curr_func
->local_vars
[i
].pc_end
) )
1131 if( strcmp(name
, curr_func
->local_vars
[i
].name
) == 0 )
1134 * OK, we found it. Now figure out what to do with this.
1136 if( curr_func
->local_vars
[i
].regno
!= 0 )
1139 * Register variable. Point to DEBUG_context field.
1141 value
->addr
.off
= ((DWORD
)&DEBUG_context
) +
1142 reg_ofs
[curr_func
->local_vars
[i
].regno
- 1];
1143 value
->cookie
= DV_HOST
;
1147 value
->addr
.off
= ebp
+ curr_func
->local_vars
[i
].offset
;
1148 value
->cookie
= DV_TARGET
;
1150 value
->addr
.seg
= 0;
1151 value
->type
= curr_func
->local_vars
[i
].type
;
1161 DEBUG_InfoLocals(void)
1163 struct name_hash
* curr_func
;
1170 if( DEBUG_GetCurrentFrame(&curr_func
, &eip
, &ebp
) == FALSE
)
1175 for(i
=0; i
< curr_func
->n_locals
; i
++ )
1178 * Test the range of validity of the local variable. This
1179 * comes up with RBRAC/LBRAC stabs in particular.
1181 if( (curr_func
->local_vars
[i
].pc_start
!= 0)
1182 && ((eip
- curr_func
->value
.addr
.off
)
1183 < curr_func
->local_vars
[i
].pc_start
) )
1188 if( (curr_func
->local_vars
[i
].pc_end
!= 0)
1189 && ((eip
- curr_func
->value
.addr
.off
)
1190 > curr_func
->local_vars
[i
].pc_end
) )
1195 if( curr_func
->local_vars
[i
].regno
!= 0 )
1197 ptr
= (unsigned int *)(((DWORD
)&DEBUG_context
)
1198 + reg_ofs
[curr_func
->local_vars
[i
].regno
- 1]);
1199 DEBUG_Printf(DBG_CHN_MESG
, "%s:%s (optimized into register $%s) == 0x%8.8x\n",
1200 curr_func
->name
, curr_func
->local_vars
[i
].name
,
1201 reg_name
[curr_func
->local_vars
[i
].regno
- 1],
1206 DEBUG_READ_MEM_VERBOSE((void*)(ebp
+ curr_func
->local_vars
[i
].offset
),
1208 DEBUG_Printf(DBG_CHN_MESG
, "%s:%s == 0x%8.8x\n",
1209 curr_func
->name
, curr_func
->local_vars
[i
].name
, val
);
1217 DEBUG_SetSymbolSize(struct name_hash
* sym
, unsigned int len
)
1219 sym
->symbol_size
= len
;
1225 DEBUG_SetSymbolBPOff(struct name_hash
* sym
, unsigned int off
)
1227 sym
->breakpoint_offset
= off
;
1233 DEBUG_GetSymbolAddr(struct name_hash
* sym
, DBG_ADDR
* addr
)
1236 *addr
= sym
->value
.addr
;
1241 int DEBUG_SetLocalSymbolType(struct wine_locals
* sym
, struct datatype
* type
)