Commit 52c7534f authored by Eric Pouech's avatar Eric Pouech Committed by Alexandre Julliard

Started handling of several symbols with the same name.

Fixed trampoline identification.
parent 36eed034
...@@ -407,7 +407,7 @@ void DEBUG_AddBreakpointFromLineno(int lineno) ...@@ -407,7 +407,7 @@ void DEBUG_AddBreakpointFromLineno(int lineno)
DEBUG_AddBreakpoint( &value, NULL ); DEBUG_AddBreakpoint( &value, NULL );
} }
/*********************************************************************** /***********************************************************************
* DEBUG_AddWatchpoint * DEBUG_AddWatchpoint
* *
* Add a watchpoint. * Add a watchpoint.
...@@ -482,11 +482,11 @@ void DEBUG_AddWatchpoint( const DBG_VALUE *_value, BOOL is_write ) ...@@ -482,11 +482,11 @@ void DEBUG_AddWatchpoint( const DBG_VALUE *_value, BOOL is_write )
* *
* Add a watchpoint from a symbol name (and eventually a line #) * Add a watchpoint from a symbol name (and eventually a line #)
*/ */
void DEBUG_AddWatchpointFromId(const char *name, int lineno) void DEBUG_AddWatchpointFromId(const char *name)
{ {
DBG_VALUE value; DBG_VALUE value;
if( DEBUG_GetSymbolValue(name, lineno, &value, TRUE) ) if( DEBUG_GetSymbolValue(name, -1, &value, TRUE) )
DEBUG_AddWatchpoint( &value, 1 ); DEBUG_AddWatchpoint( &value, 1 );
else else
DEBUG_Printf(DBG_CHN_MESG, "Unable to add watchpoint\n"); DEBUG_Printf(DBG_CHN_MESG, "Unable to add watchpoint\n");
...@@ -876,7 +876,7 @@ enum exec_mode DEBUG_RestartExecution( enum exec_mode mode, int count ) ...@@ -876,7 +876,7 @@ enum exec_mode DEBUG_RestartExecution( enum exec_mode mode, int count )
* FIXME - we need to check for things like thunks or trampolines, * FIXME - we need to check for things like thunks or trampolines,
* as the actual function may in fact have debug info. * as the actual function may in fact have debug info.
*/ */
if( ch == 0xe8 ) if ( ch == 0xe8 )
{ {
DEBUG_READ_MEM((void*)(instr + 1), &delta, sizeof(delta)); DEBUG_READ_MEM((void*)(instr + 1), &delta, sizeof(delta));
addr2 = addr; addr2 = addr;
......
...@@ -202,7 +202,7 @@ break_command: ...@@ -202,7 +202,7 @@ break_command:
watch_command: watch_command:
tWATCH '*' expr_addr tEOL { DEBUG_AddWatchpoint( &$3, 1 ); DEBUG_FreeExprMem(); } tWATCH '*' expr_addr tEOL { DEBUG_AddWatchpoint( &$3, 1 ); DEBUG_FreeExprMem(); }
| tWATCH tIDENTIFIER tEOL { DEBUG_AddWatchpointFromId($2, -1); } | tWATCH tIDENTIFIER tEOL { DEBUG_AddWatchpointFromId($2); }
info_command: info_command:
tINFO tBREAK tEOL { DEBUG_InfoBreakpoints(); } tINFO tBREAK tEOL { DEBUG_InfoBreakpoints(); }
......
...@@ -208,6 +208,7 @@ extern DBG_THREAD* DEBUG_CurrThread; ...@@ -208,6 +208,7 @@ extern DBG_THREAD* DEBUG_CurrThread;
extern DWORD DEBUG_CurrTid; extern DWORD DEBUG_CurrTid;
extern DWORD DEBUG_CurrPid; extern DWORD DEBUG_CurrPid;
extern CONTEXT DEBUG_context; extern CONTEXT DEBUG_context;
extern BOOL DEBUG_interactiveP;
#define DEBUG_READ_MEM(addr, buf, len) \ #define DEBUG_READ_MEM(addr, buf, len) \
(ReadProcessMemory(DEBUG_CurrProcess->handle, (addr), (buf), (len), NULL)) (ReadProcessMemory(DEBUG_CurrProcess->handle, (addr), (buf), (len), NULL))
...@@ -230,7 +231,7 @@ typedef struct tagDBG_MODULE { ...@@ -230,7 +231,7 @@ typedef struct tagDBG_MODULE {
char* module_name; char* module_name;
enum DbgInfoLoad dil; enum DbgInfoLoad dil;
enum DbgModuleType type; enum DbgModuleType type;
unsigned char main; unsigned short main : 1;
short int dbg_index; short int dbg_index;
HMODULE handle; HMODULE handle;
struct tagMSC_DBG_INFO* msc_info; struct tagMSC_DBG_INFO* msc_info;
...@@ -255,7 +256,7 @@ extern void DEBUG_AddBreakpoint( const DBG_VALUE *addr, BOOL (*func)(void) ); ...@@ -255,7 +256,7 @@ extern void DEBUG_AddBreakpoint( const DBG_VALUE *addr, BOOL (*func)(void) );
extern void DEBUG_AddBreakpointFromId( const char *name, int lineno ); extern void DEBUG_AddBreakpointFromId( const char *name, int lineno );
extern void DEBUG_AddBreakpointFromLineno( int lineno ); extern void DEBUG_AddBreakpointFromLineno( int lineno );
extern void DEBUG_AddWatchpoint( const DBG_VALUE *addr, int is_write ); extern void DEBUG_AddWatchpoint( const DBG_VALUE *addr, int is_write );
extern void DEBUG_AddWatchpointFromId( const char *name, int lineno ); extern void DEBUG_AddWatchpointFromId( const char *name );
extern void DEBUG_DelBreakpoint( int num ); extern void DEBUG_DelBreakpoint( int num );
extern void DEBUG_EnableBreakpoint( int num, BOOL enable ); extern void DEBUG_EnableBreakpoint( int num, BOOL enable );
extern void DEBUG_InfoBreakpoints(void); extern void DEBUG_InfoBreakpoints(void);
...@@ -314,8 +315,8 @@ extern struct name_hash * DEBUG_AddSymbol( const char *name, ...@@ -314,8 +315,8 @@ extern struct name_hash * DEBUG_AddSymbol( const char *name,
const DBG_VALUE *addr, const DBG_VALUE *addr,
const char *sourcefile, const char *sourcefile,
int flags); int flags);
extern BOOL DEBUG_GetSymbolValue( const char * name, const int lineno, extern int DEBUG_GetSymbolValue( const char * name, const int lineno,
DBG_VALUE *addr, int ); DBG_VALUE *addr, int );
extern BOOL DEBUG_SetSymbolValue( const char * name, const DBG_VALUE *addr ); extern BOOL DEBUG_SetSymbolValue( const char * name, const DBG_VALUE *addr );
extern const char * DEBUG_FindNearestSymbol( const DBG_ADDR *addr, int flag, extern const char * DEBUG_FindNearestSymbol( const DBG_ADDR *addr, int flag,
struct name_hash ** rtn, struct name_hash ** rtn,
...@@ -390,6 +391,7 @@ extern DBG_MODULE* DEBUG_AddModule(const char* name, enum DbgModuleType type, ...@@ -390,6 +391,7 @@ extern DBG_MODULE* DEBUG_AddModule(const char* name, enum DbgModuleType type,
void* mod_addr, u_long size, HMODULE hmod); void* mod_addr, u_long size, HMODULE hmod);
extern DBG_MODULE* DEBUG_FindModuleByName(const char* name, enum DbgModuleType type); extern DBG_MODULE* DEBUG_FindModuleByName(const char* name, enum DbgModuleType type);
extern DBG_MODULE* DEBUG_FindModuleByHandle(HANDLE handle, enum DbgModuleType type); extern DBG_MODULE* DEBUG_FindModuleByHandle(HANDLE handle, enum DbgModuleType type);
extern DBG_MODULE* DEBUG_FindModuleByAddr(void* addr, enum DbgModuleType type);
extern DBG_MODULE* DEBUG_GetProcessMainModule(DBG_PROCESS* process); extern DBG_MODULE* DEBUG_GetProcessMainModule(DBG_PROCESS* process);
extern DBG_MODULE* DEBUG_RegisterPEModule(HMODULE, u_long load_addr, u_long size, extern DBG_MODULE* DEBUG_RegisterPEModule(HMODULE, u_long load_addr, u_long size,
const char* name); const char* name);
......
...@@ -181,14 +181,13 @@ DEBUG_ResortSymbols(void) ...@@ -181,14 +181,13 @@ DEBUG_ResortSymbols(void)
* Add a symbol to the table. * Add a symbol to the table.
*/ */
struct name_hash * struct name_hash *
DEBUG_AddSymbol( const char * name, const DBG_VALUE *value, const char * source, DEBUG_AddSymbol( const char * name, const DBG_VALUE *value,
int flags) const char * source, int flags)
{ {
struct name_hash * new; struct name_hash * new;
struct name_hash *nh; struct name_hash *nh;
static char prev_source[PATH_MAX] = {'\0', }; static char prev_source[PATH_MAX] = {'\0', };
static char * prev_duped_source = NULL; static char * prev_duped_source = NULL;
char * c;
int hash; int hash;
assert(value->cookie == DV_TARGET || value->cookie == DV_HOST); assert(value->cookie == DV_TARGET || value->cookie == DV_HOST);
...@@ -284,24 +283,17 @@ DEBUG_AddSymbol( const char * name, const DBG_VALUE *value, const char * source, ...@@ -284,24 +283,17 @@ DEBUG_AddSymbol( const char * name, const DBG_VALUE *value, const char * source,
* calling things and the GCC way of calling things. In general we * calling things and the GCC way of calling things. In general we
* always want to step through. * always want to step through.
*/ */
if( source != NULL ) if ( source != NULL ) {
{ int len = strlen(source);
c = strrchr(source, '.');
if( c != NULL && strcmp(c, ".s") == 0 ) if (len > 2 && source[len-2] == '.' && source[len-1] == 's') {
{ char* c = strrchr(source - 2, '/');
c = strrchr(source, '/'); if (c != NULL) {
if( c != NULL ) if (strcmp(c + 1, "asmrelay.s") == 0)
{
c++;
if( (strcmp(c, "callfrom16.s") == 0)
|| (strcmp(c, "callto16.s") == 0)
|| (strcmp(c, "call32.s") == 0) )
{
new->flags |= SYM_TRAMPOLINE; new->flags |= SYM_TRAMPOLINE;
} }
} }
} }
}
sortlist_valid = FALSE; sortlist_valid = FALSE;
return new; return new;
...@@ -341,52 +333,79 @@ BOOL DEBUG_Normalize(struct name_hash * nh ) ...@@ -341,52 +333,79 @@ BOOL DEBUG_Normalize(struct name_hash * nh )
* *
* Get the address of a named symbol. * Get the address of a named symbol.
*/ */
BOOL DEBUG_GetSymbolValue( const char * name, const int lineno, static int DEBUG_GSV_Helper(const char* name, const int lineno,
DBG_VALUE *value, int bp_flag ) DBG_VALUE* value, int num, int bp_flag)
{ {
struct name_hash *nh; struct name_hash* nh;
int i = 0;
for(nh = name_hash_table[name_hash(name)]; nh; nh = nh->next) DBG_ADDR addr;
for (nh = name_hash_table[name_hash(name)]; nh; nh = nh->next)
{
if ((nh->flags & SYM_INVALID) != 0) continue;
if (!strcmp(nh->name, name) && DEBUG_GetLineNumberAddr( nh, lineno, &addr, bp_flag ))
{ {
if( (nh->flags & SYM_INVALID) != 0 ) if (i >= num) return num + 1;
{ value[i].addr = addr;
continue; value[i].type = nh->value.type;
} value[i].cookie = nh->value.cookie;
i++;
if (!strcmp(nh->name, name)) break;
} }
}
return i;
}
if (!nh && (name[0] != '_')) BOOL DEBUG_GetSymbolValue( const char * name, const int lineno,
{ DBG_VALUE *rtn, int bp_flag )
char buffer[256]; {
#define NUMDBGV 10
/* FIXME: NUMDBGV should be made variable */
DBG_VALUE value[NUMDBGV];
DBG_VALUE vtmp;
int num, i;
num = DEBUG_GSV_Helper(name, lineno, value, NUMDBGV, bp_flag);
if (!num && (name[0] != '_'))
{
char buffer[256];
assert(strlen(name) < sizeof(buffer) - 2); /* one for '_', one for '\0' */ assert(strlen(name) < sizeof(buffer) - 2); /* one for '_', one for '\0' */
buffer[0] = '_'; buffer[0] = '_';
strcpy(buffer+1, name); strcpy(buffer + 1, name);
for(nh = name_hash_table[name_hash(buffer)]; nh; nh = nh->next) num = DEBUG_GSV_Helper(buffer, lineno, value, NUMDBGV, bp_flag);
{ }
if( (nh->flags & SYM_INVALID) != 0 )
{ /* now get the local symbols if any */
continue; if (DEBUG_GetStackSymbolValue(name, &vtmp) && num < NUMDBGV)
} {
if (!strcmp(nh->name, buffer)) break; value[num] = vtmp;
} num++;
} }
/* if (num == 0) {
* If we don't have anything here, then try and see if this return FALSE;
* is a local symbol to the current stack frame. No matter } else if (!DEBUG_interactiveP || num == 1) {
* what, we have nothing more to do, so we let that function i = 0;
* decide what we ultimately return. } else {
*/ char* ptr;
if (!nh) if (num == NUMDBGV+1) {
{ DEBUG_Printf(DBG_CHN_MESG, "Too many addresses for symbol '%s', limiting the first %d\n", name, NUMDBGV);
return DEBUG_GetStackSymbolValue(name, value); num = NUMDBGV;
} }
DEBUG_Printf(DBG_CHN_MESG, "Many symbols with name '%s', choose the one you want (<cr> to abort):\n", name);
value->type = nh->value.type; for (i = 0; i < num; i++) {
value->cookie = nh->value.cookie; DEBUG_Printf(DBG_CHN_MESG, "[%d]: ", i + 1);
return DEBUG_GetLineNumberAddr( nh, lineno, &value->addr, bp_flag ); DEBUG_PrintAddress( &value[i].addr, DEBUG_GetSelectorType(value[i].addr.seg), TRUE);
DEBUG_Printf(DBG_CHN_MESG, "\n");
}
do {
ptr = readline("=> ");
if (!*ptr) return FALSE;
i = atoi(ptr);
} while (i < 0 || i >= num);
}
*rtn = value[i];
return TRUE;
} }
/*********************************************************************** /***********************************************************************
...@@ -495,6 +514,8 @@ const char * DEBUG_FindNearestSymbol( const DBG_ADDR *addr, int flag, ...@@ -495,6 +514,8 @@ const char * DEBUG_FindNearestSymbol( const DBG_ADDR *addr, int flag,
int i; int i;
char linebuff[16]; char linebuff[16];
unsigned val; unsigned val;
DBG_MODULE* module;
char modbuf[256];
if( rtn != NULL ) if( rtn != NULL )
{ {
...@@ -666,6 +687,16 @@ const char * DEBUG_FindNearestSymbol( const DBG_ADDR *addr, int flag, ...@@ -666,6 +687,16 @@ const char * DEBUG_FindNearestSymbol( const DBG_ADDR *addr, int flag,
} }
} }
module = DEBUG_FindModuleByAddr((void*)DEBUG_ToLinear(addr), DMT_UNKNOWN);
if (module) {
char* ptr = strrchr(module->module_name, '/');
if (!ptr++) ptr = module->module_name;
sprintf( modbuf, " in %s", ptr);
}
else
modbuf[0] = '\0';
if( (nearest->sourcefile != NULL) && (flag == TRUE) if( (nearest->sourcefile != NULL) && (flag == TRUE)
&& (addr->off - nearest->value.addr.off < 0x100000) ) && (addr->off - nearest->value.addr.off < 0x100000) )
{ {
...@@ -702,25 +733,25 @@ const char * DEBUG_FindNearestSymbol( const DBG_ADDR *addr, int flag, ...@@ -702,25 +733,25 @@ const char * DEBUG_FindNearestSymbol( const DBG_ADDR *addr, int flag,
sourcefile = strrchr( nearest->sourcefile, '/' ); sourcefile = strrchr( nearest->sourcefile, '/' );
if (!sourcefile) sourcefile = nearest->sourcefile; if (!sourcefile) sourcefile = nearest->sourcefile;
else sourcefile++; else sourcefile++;
if (addr->off == nearest->value.addr.off) if (addr->off == nearest->value.addr.off)
sprintf( name_buffer, "%s%s [%s%s]", nearest->name, sprintf( name_buffer, "%s%s [%s%s]%s", nearest->name,
arglist, sourcefile, lineinfo); arglist, sourcefile, lineinfo, modbuf);
else else
sprintf( name_buffer, "%s+0x%lx%s [%s%s]", nearest->name, sprintf( name_buffer, "%s+0x%lx%s [%s%s]%s", nearest->name,
addr->off - nearest->value.addr.off, addr->off - nearest->value.addr.off,
arglist, sourcefile, lineinfo ); arglist, sourcefile, lineinfo, modbuf );
} }
else else
{ {
if (addr->off == nearest->value.addr.off) if (addr->off == nearest->value.addr.off)
sprintf( name_buffer, "%s%s", nearest->name, arglist); sprintf( name_buffer, "%s%s%s", nearest->name, arglist, modbuf);
else { else {
if (addr->seg && (nearest->value.addr.seg!=addr->seg)) if (addr->seg && (nearest->value.addr.seg!=addr->seg))
return NULL; return NULL;
else else
sprintf( name_buffer, "%s+0x%lx%s", nearest->name, sprintf( name_buffer, "%s+0x%lx%s%s", nearest->name,
addr->off - nearest->value.addr.off, arglist); addr->off - nearest->value.addr.off, arglist, modbuf);
} }
} }
return name_buffer; return name_buffer;
...@@ -732,7 +763,7 @@ const char * DEBUG_FindNearestSymbol( const DBG_ADDR *addr, int flag, ...@@ -732,7 +763,7 @@ const char * DEBUG_FindNearestSymbol( const DBG_ADDR *addr, int flag,
* *
* Read a symbol file into the hash table. * Read a symbol file into the hash table.
*/ */
void DEBUG_ReadSymbolTable( const char * filename ) void DEBUG_ReadSymbolTable( const char* filename )
{ {
FILE * symbolfile; FILE * symbolfile;
DBG_VALUE value; DBG_VALUE value;
......
...@@ -76,10 +76,13 @@ DBG_MODULE* DEBUG_FindModuleByAddr(void* addr, enum DbgModuleType type) ...@@ -76,10 +76,13 @@ DBG_MODULE* DEBUG_FindModuleByAddr(void* addr, enum DbgModuleType type)
for (i = 0; i < DEBUG_CurrProcess->num_modules; i++) { for (i = 0; i < DEBUG_CurrProcess->num_modules; i++) {
if ((type == DMT_UNKNOWN || type == amod[i]->type) && if ((type == DMT_UNKNOWN || type == amod[i]->type) &&
(u_long)addr >= (u_long)amod[i]->load_addr && (u_long)addr >= (u_long)amod[i]->load_addr &&
(!res || res->load_addr < amod[i]->load_addr)) (u_long)addr < (u_long)amod[i]->load_addr + (u_long)amod[i]->size) {
res = amod[i]; /* amod[i] contains it... check against res now */
if (!res || res->load_addr < amod[i]->load_addr)
res = amod[i];
}
} }
return res; return res;
} }
/*********************************************************************** /***********************************************************************
...@@ -367,7 +370,7 @@ enum DbgInfoLoad DEBUG_RegisterPEDebugInfo(DBG_MODULE* wmod, HANDLE hFile, ...@@ -367,7 +370,7 @@ enum DbgInfoLoad DEBUG_RegisterPEDebugInfo(DBG_MODULE* wmod, HANDLE hFile,
((names = DBG_alloc(sizeof(names[0]) * exports.NumberOfNames))) && ((names = DBG_alloc(sizeof(names[0]) * exports.NumberOfNames))) &&
DEBUG_READ_MEM_VERBOSE((void*)(base + (DWORD)exports.AddressOfNames), DEBUG_READ_MEM_VERBOSE((void*)(base + (DWORD)exports.AddressOfNames),
names, sizeof(names[0]) * exports.NumberOfNames)) { names, sizeof(names[0]) * exports.NumberOfNames)) {
for (i = 0; i < exports.NumberOfNames; i++) { for (i = 0; i < exports.NumberOfNames; i++) {
if (!names[i] || if (!names[i] ||
!DEBUG_READ_MEM_VERBOSE((void*)(base + names[i]), bufstr, sizeof(bufstr))) !DEBUG_READ_MEM_VERBOSE((void*)(base + names[i]), bufstr, sizeof(bufstr)))
......
...@@ -28,6 +28,7 @@ DBG_THREAD* DEBUG_CurrThread = NULL; ...@@ -28,6 +28,7 @@ DBG_THREAD* DEBUG_CurrThread = NULL;
DWORD DEBUG_CurrTid; DWORD DEBUG_CurrTid;
DWORD DEBUG_CurrPid; DWORD DEBUG_CurrPid;
CONTEXT DEBUG_context; CONTEXT DEBUG_context;
BOOL DEBUG_interactiveP = FALSE;
int curr_frame = 0; int curr_frame = 0;
static char* DEBUG_LastCmdLine = NULL; static char* DEBUG_LastCmdLine = NULL;
...@@ -44,7 +45,7 @@ void DEBUG_Output(int chn, const char* buffer, int len) ...@@ -44,7 +45,7 @@ void DEBUG_Output(int chn, const char* buffer, int len)
int DEBUG_Printf(int chn, const char* format, ...) int DEBUG_Printf(int chn, const char* format, ...)
{ {
char buf[1024]; static char buf[4*1024];
va_list valist; va_list valist;
int len; int len;
...@@ -499,6 +500,7 @@ static BOOL DEBUG_HandleException(EXCEPTION_RECORD *rec, BOOL first_chance, BOOL ...@@ -499,6 +500,7 @@ static BOOL DEBUG_HandleException(EXCEPTION_RECORD *rec, BOOL first_chance, BOOL
DEBUG_CurrThread->dbg_exec_mode, DEBUG_CurrThread->dbg_exec_count); DEBUG_CurrThread->dbg_exec_mode, DEBUG_CurrThread->dbg_exec_count);
if (DEBUG_ExceptionProlog(is_debug, force, rec->ExceptionCode)) { if (DEBUG_ExceptionProlog(is_debug, force, rec->ExceptionCode)) {
DEBUG_interactiveP = TRUE;
while ((ret = DEBUG_Parser())) { while ((ret = DEBUG_Parser())) {
if (DEBUG_ValidateRegisters()) { if (DEBUG_ValidateRegisters()) {
if (DEBUG_CurrThread->dbg_exec_mode != EXEC_PASS || first_chance) if (DEBUG_CurrThread->dbg_exec_mode != EXEC_PASS || first_chance)
...@@ -506,6 +508,7 @@ static BOOL DEBUG_HandleException(EXCEPTION_RECORD *rec, BOOL first_chance, BOOL ...@@ -506,6 +508,7 @@ static BOOL DEBUG_HandleException(EXCEPTION_RECORD *rec, BOOL first_chance, BOOL
DEBUG_Printf(DBG_CHN_MESG, "Cannot pass on last chance exception. You must use cont\n"); DEBUG_Printf(DBG_CHN_MESG, "Cannot pass on last chance exception. You must use cont\n");
} }
} }
DEBUG_interactiveP = FALSE;
} }
*cont = DEBUG_ExceptionEpilog(); *cont = DEBUG_ExceptionEpilog();
...@@ -861,7 +864,7 @@ int DEBUG_main(int argc, char** argv) ...@@ -861,7 +864,7 @@ int DEBUG_main(int argc, char** argv)
} }
DEBUG_Printf(DBG_CHN_MESG, "WineDbg starting... "); DEBUG_Printf(DBG_CHN_MESG, "WineDbg starting... ");
if (argc == 3) { if (argc == 3) {
HANDLE hEvent; HANDLE hEvent;
DWORD pid; DWORD pid;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment