From b3ec4b91afde477c2fed3b7bf7faf99587836085 Mon Sep 17 00:00:00 2001 From: Ulrich Weigand <weigand@informatik.uni-erlangen.de> Date: Sat, 13 Nov 1999 20:58:45 +0000 Subject: [PATCH] Made debugger compile and marginally work on non-Intel archs. --- debugger/break.c | 45 +++++++++++++++++++++++-------------------- debugger/db_disasm.c | 11 +++++++++++ debugger/dbg.y | 46 +++++++++++++++----------------------------- debugger/expr.c | 4 ++++ debugger/hash.c | 5 +++++ debugger/memory.c | 4 ++++ debugger/registers.c | 20 +++++++++++++++++-- debugger/source.c | 31 +++++++++++++++++++++-------- debugger/stack.c | 11 ++++++++++- include/debugger.h | 10 ++++++++++ 10 files changed, 124 insertions(+), 63 deletions(-) diff --git a/debugger/break.c b/debugger/break.c index 5f445aa1c1a..68150d15de9 100644 --- a/debugger/break.c +++ b/debugger/break.c @@ -76,6 +76,7 @@ static void DEBUG_SetOpcode( const DBG_ADDR *addr, BYTE op ) */ static BOOL DEBUG_IsStepOverInstr() { +#ifdef __i386__ BYTE *instr = (BYTE *)CTX_SEG_OFF_TO_LIN( &DEBUG_context, CS_reg(&DEBUG_context), EIP_reg(&DEBUG_context) ); @@ -133,6 +134,9 @@ static BOOL DEBUG_IsStepOverInstr() return FALSE; } } +#else + return FALSE; +#endif } @@ -144,6 +148,7 @@ static BOOL DEBUG_IsStepOverInstr() */ BOOL DEBUG_IsFctReturn(void) { +#ifdef __i386__ BYTE *instr = (BYTE *)CTX_SEG_OFF_TO_LIN( &DEBUG_context, CS_reg(&DEBUG_context), EIP_reg(&DEBUG_context) ); @@ -159,6 +164,9 @@ BOOL DEBUG_IsFctReturn(void) return FALSE; } } +#else + return FALSE; +#endif } @@ -391,18 +399,13 @@ BOOL DEBUG_ShouldContinue( enum exec_mode mode, int * count ) DBG_ADDR cond_addr; int bpnum; struct list_id list; - TDB *pTask = (TDB*)GlobalLock16( GetCurrentTask() ); +#ifdef __i386__ /* If not single-stepping, back up over the int3 instruction */ if (!(EFL_reg(&DEBUG_context) & STEP_FLAG)) EIP_reg(&DEBUG_context)--; +#endif - addr.seg = CS_reg(&DEBUG_context); - addr.off = EIP_reg(&DEBUG_context); - if (ISV86(&DEBUG_context)) addr.seg |= (DWORD)(pTask?(pTask->hModule):0)<<16; else - if (IS_SELECTOR_SYSTEM(addr.seg)) addr.seg = 0; - - GlobalUnlock16( GetCurrentTask() ); - + DEBUG_GetCurrentAddress( &addr ); bpnum = DEBUG_FindBreakpoint( &addr ); breakpoints[0].enabled = 0; /* disable the step-over breakpoint */ @@ -493,10 +496,12 @@ BOOL DEBUG_ShouldContinue( enum exec_mode mode, int * count ) } } +#ifdef __i386__ /* If there's no breakpoint and we are not single-stepping, then we */ /* must have encountered an int3 in the Windows program; let's skip it. */ if ((bpnum == -1) && !(EFL_reg(&DEBUG_context) & STEP_FLAG)) EIP_reg(&DEBUG_context)++; +#endif /* no breakpoint, continue if in continuous mode */ return (mode == EXEC_CONT || mode == EXEC_PASS || mode == EXEC_FINISH); @@ -516,17 +521,10 @@ enum exec_mode DEBUG_RestartExecution( enum exec_mode mode, int count ) int bp; int delta; int status; - unsigned int * value; enum exec_mode ret_mode; BYTE *instr; - TDB *pTask = (TDB*)GlobalLock16( GetCurrentTask() ); - addr.seg = CS_reg(&DEBUG_context); - addr.off = EIP_reg(&DEBUG_context); - if (ISV86(&DEBUG_context)) addr.seg |= (DWORD)(pTask?(pTask->hModule):0)<<16; else - if (IS_SELECTOR_SYSTEM(addr.seg)) addr.seg = 0; - - GlobalUnlock16( GetCurrentTask() ); + DEBUG_GetCurrentAddress( &addr ); /* * This is the mode we will be running in after we finish. We would like @@ -559,9 +557,7 @@ enum exec_mode DEBUG_RestartExecution( enum exec_mode mode, int count ) mode = ret_mode = EXEC_STEPI_INSTR; } - instr = (BYTE *)CTX_SEG_OFF_TO_LIN( &DEBUG_context, - CS_reg(&DEBUG_context), - EIP_reg(&DEBUG_context) ); + instr = DBG_ADDR_TO_LIN( &addr ); /* * See if the function we are stepping into has debug info * and line numbers. If not, then we step over it instead. @@ -615,7 +611,9 @@ enum exec_mode DEBUG_RestartExecution( enum exec_mode mode, int count ) { case EXEC_CONT: /* Continuous execution */ case EXEC_PASS: /* Continue, passing exception */ +#ifdef __i386__ EFL_reg(&DEBUG_context) &= ~STEP_FLAG; +#endif DEBUG_SetBreakpoints( TRUE ); break; @@ -626,9 +624,10 @@ enum exec_mode DEBUG_RestartExecution( enum exec_mode mode, int count ) * off the stack, and we set the breakpoint there instead of the * address just after the call. */ - value = (unsigned int *) ESP_reg(&DEBUG_context) + 2; - addr.off = *value; +#ifdef __i386__ + addr.off = *((unsigned int *) ESP_reg(&DEBUG_context) + 2); EFL_reg(&DEBUG_context) &= ~STEP_FLAG; +#endif breakpoints[0].addr = addr; breakpoints[0].enabled = TRUE; breakpoints[0].in_use = TRUE; @@ -642,7 +641,9 @@ enum exec_mode DEBUG_RestartExecution( enum exec_mode mode, int count ) case EXEC_STEP_OVER: /* Stepping over a call */ if (DEBUG_IsStepOverInstr()) { +#ifdef __i386__ EFL_reg(&DEBUG_context) &= ~STEP_FLAG; +#endif DEBUG_Disasm(&addr, FALSE); breakpoints[0].addr = addr; breakpoints[0].enabled = TRUE; @@ -656,7 +657,9 @@ enum exec_mode DEBUG_RestartExecution( enum exec_mode mode, int count ) case EXEC_STEP_INSTR: /* Single-stepping an instruction */ case EXEC_STEPI_INSTR: /* Single-stepping an instruction */ +#ifdef __i386__ EFL_reg(&DEBUG_context) |= STEP_FLAG; +#endif break; } return ret_mode; diff --git a/debugger/db_disasm.c b/debugger/db_disasm.c index 6ac7b19ceb4..42cf385479f 100644 --- a/debugger/db_disasm.c +++ b/debugger/db_disasm.c @@ -65,6 +65,8 @@ #include <stdio.h> #include "debugger.h" +#ifdef __i386__ + /* * Switch to disassemble 16-bit code. */ @@ -1611,3 +1613,12 @@ void DEBUG_Disasm( DBG_ADDR *addr, int display ) } } } + +#else /* __i386__ */ + +void DEBUG_Disasm( DBG_ADDR *addr, int display ) +{ +} + +#endif /* __i386__ */ + diff --git a/debugger/dbg.y b/debugger/dbg.y index 49969ef05cc..e6f453dce45 100644 --- a/debugger/dbg.y +++ b/debugger/dbg.y @@ -252,16 +252,7 @@ break_command: } | tBREAK tNUM tEOL { struct name_hash *nh; DBG_ADDR addr; - TDB *pTask = (TDB*)GlobalLock16( GetCurrentTask() ); - - addr.type = NULL; - addr.seg = CS_reg(&DEBUG_context); - addr.off = EIP_reg(&DEBUG_context); - - if (ISV86(&DEBUG_context)) - addr.seg |= (DWORD)(pTask?(pTask->hModule):0)<<16; - DBG_FIX_ADDR_SEG( &addr, CS_reg(&DEBUG_context) ); - GlobalUnlock16( GetCurrentTask() ); + DEBUG_GetCurrentAddress( &addr ); DEBUG_FindNearestSymbol(&addr, TRUE, &nh, 0, NULL); if( nh != NULL ) @@ -277,15 +268,7 @@ break_command: } | tBREAK tEOL { DBG_ADDR addr; - TDB *pTask = (TDB*)GlobalLock16( GetCurrentTask() ); - - addr.type = NULL; - addr.seg = CS_reg(&DEBUG_context); - addr.off = EIP_reg(&DEBUG_context); - - if (ISV86(&DEBUG_context)) - addr.seg |= (DWORD)(pTask?(pTask->hModule):0)<<16; - GlobalUnlock16( GetCurrentTask() ); + DEBUG_GetCurrentAddress( &addr ); DEBUG_AddBreakpoint( &addr ); } @@ -495,11 +478,15 @@ static void DEBUG_Main( BOOL is_debug ) if (!is_debug) { +#ifdef __i386__ if (IS_SELECTOR_SYSTEM(CS_reg(&DEBUG_context))) fprintf( stderr, " in 32-bit code (0x%08lx).\n", EIP_reg(&DEBUG_context)); else fprintf( stderr, " in 16-bit code (%04x:%04lx).\n", (WORD)CS_reg(&DEBUG_context), EIP_reg(&DEBUG_context) ); +#else + fprintf( stderr, " (%p).\n", GET_IP(&DEBUG_context) ); +#endif } if (!loaded_symbols) @@ -562,22 +549,18 @@ static void DEBUG_Main( BOOL is_debug ) if (!is_debug || !DEBUG_ShouldContinue( dbg_exec_mode, &dbg_exec_count )) { DBG_ADDR addr; - TDB *pTask = (TDB*)GlobalLock16( GetCurrentTask() ); - - addr.seg = CS_reg(&DEBUG_context); - addr.off = EIP_reg(&DEBUG_context); - if (ISV86(&DEBUG_context)) addr.seg |= (DWORD)(pTask?(pTask->hModule):0)<<16; - addr.type = NULL; - DBG_FIX_ADDR_SEG( &addr, 0 ); - - GlobalUnlock16( GetCurrentTask() ); + DEBUG_GetCurrentAddress( &addr ); DEBUG_Freeze( TRUE ); /* Put the display in a correct state */ USER_Driver->pBeginDebugging(); +#ifdef __i386__ newmode = ISV86(&DEBUG_context) ? 16 : IS_SELECTOR_32BIT(addr.seg) ? 32 : 16; +#else + newmode = 32; +#endif if (newmode != dbg_mode) fprintf(stderr,"In %d bit mode.\n", dbg_mode = newmode); @@ -587,6 +570,7 @@ static void DEBUG_Main( BOOL is_debug ) { DEBUG_InfoRegisters(); DEBUG_InfoStack(); +#ifdef __i386__ if (dbg_mode == 16) { LDT_Print( SELECTOR_TO_ENTRY(DS_reg(&DEBUG_context)), 1 ); @@ -594,6 +578,7 @@ static void DEBUG_Main( BOOL is_debug ) LDT_Print( SELECTOR_TO_ENTRY(ES_reg(&DEBUG_context)), 1 ); } LDT_Print( SELECTOR_TO_ENTRY(FS_reg(&DEBUG_context)), 1 ); +#endif DEBUG_BackTrace(); } else @@ -626,9 +611,8 @@ static void DEBUG_Main( BOOL is_debug ) issue_prompt(); yyparse(); flush_symbols(); - addr.seg = CS_reg(&DEBUG_context) | (addr.seg&0xffff0000); - addr.off = EIP_reg(&DEBUG_context); - DBG_FIX_ADDR_SEG( &addr, 0 ); + + DEBUG_GetCurrentAddress( &addr ); ret_ok = DEBUG_ValidateRegisters(); if (ret_ok) ret_ok = DBG_CHECK_READ_PTR( &addr, 1 ); } while (!ret_ok); diff --git a/debugger/expr.c b/debugger/expr.c index 41684769d79..fbee595d173 100644 --- a/debugger/expr.c +++ b/debugger/expr.c @@ -417,10 +417,12 @@ DEBUG_EvalExpr(struct expr * exp) rtn.type = DEBUG_TypeIntConst; exp->un.rgister.result = DEBUG_GetRegister(exp->un.rgister.reg); rtn.off = (unsigned int) &exp->un.rgister.result; +#ifdef __i386__ if( exp->un.rgister.reg == REG_EIP ) rtn.seg = CS_reg(&DEBUG_context); else rtn.seg = DS_reg(&DEBUG_context); +#endif DBG_FIX_ADDR_SEG( &rtn, 0 ); break; case EXPR_TYPE_BINOP: @@ -494,11 +496,13 @@ DEBUG_EvalExpr(struct expr * exp) case EXP_OP_SEG: rtn.seg = VAL(exp1); exp->un.binop.result = VAL(exp2); +#ifdef __i386__ if (ISV86(&DEBUG_context)) { TDB *pTask = (TDB*)GlobalLock16( GetCurrentTask() ); rtn.seg |= (DWORD)(pTask?(pTask->hModule):0)<<16; GlobalUnlock16( GetCurrentTask() ); } +#endif break; case EXP_OP_LOR: rtn.seg = 0; diff --git a/debugger/hash.c b/debugger/hash.c index ab1632feb80..8bc7cdb360e 100644 --- a/debugger/hash.c +++ b/debugger/hash.c @@ -23,6 +23,7 @@ #define PATH_MAX _MAX_PATH #endif +#ifdef __i386__ static char * reg_name[] = { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi" @@ -35,6 +36,10 @@ static unsigned reg_ofs[] = FIELD_OFFSET(CONTEXT, Esp), FIELD_OFFSET(CONTEXT, Ebp), FIELD_OFFSET(CONTEXT, Esi), FIELD_OFFSET(CONTEXT, Edi) }; +#else +static char * reg_name[] = { NULL }; /* FIXME */ +static unsigned reg_ofs[] = { 0 }; +#endif struct name_hash diff --git a/debugger/memory.c b/debugger/memory.c index 47c42ef9082..63d1d52d02e 100644 --- a/debugger/memory.c +++ b/debugger/memory.c @@ -115,6 +115,7 @@ BOOL DEBUG_checkmap_bad( const char *addr, size_t size, int rwflag) */ BOOL DEBUG_IsBadReadPtr( const DBG_ADDR *address, int size ) { +#ifdef __i386__ if (!IS_SELECTOR_V86(address->seg)) if (address->seg) /* segmented addr */ { @@ -122,6 +123,7 @@ BOOL DEBUG_IsBadReadPtr( const DBG_ADDR *address, int size ) (WORD)address->seg ), size )) return TRUE; } +#endif return DEBUG_checkmap_bad( DBG_ADDR_TO_LIN(address), size, 1); } @@ -133,6 +135,7 @@ BOOL DEBUG_IsBadReadPtr( const DBG_ADDR *address, int size ) */ BOOL DEBUG_IsBadWritePtr( const DBG_ADDR *address, int size ) { +#ifdef __i386__ if (!IS_SELECTOR_V86(address->seg)) if (address->seg) /* segmented addr */ { @@ -142,6 +145,7 @@ BOOL DEBUG_IsBadWritePtr( const DBG_ADDR *address, int size ) (WORD)address->seg ), size )) return TRUE; } +#endif return DEBUG_checkmap_bad( DBG_ADDR_TO_LIN(address), size, 0); } diff --git a/debugger/registers.c b/debugger/registers.c index bdd99064b41..4ec7b28fd36 100644 --- a/debugger/registers.c +++ b/debugger/registers.c @@ -19,6 +19,7 @@ CONTEXT DEBUG_context; */ void DEBUG_SetRegister( enum debug_regs reg, int val ) { +#ifdef __i386__ switch(reg) { case REG_EAX: EAX_reg(&DEBUG_context) = val; break; @@ -48,12 +49,14 @@ void DEBUG_SetRegister( enum debug_regs reg, int val ) case REG_IP: SET_LOWORD(EIP_reg(&DEBUG_context),val); break; case REG_SP: SET_LOWORD(ESP_reg(&DEBUG_context),val); break; } +#endif } int DEBUG_PrintRegister(enum debug_regs reg) { +#ifdef __i386__ switch(reg) { case REG_EAX: fprintf(stderr, "%%eax"); break; @@ -84,6 +87,9 @@ DEBUG_PrintRegister(enum debug_regs reg) case REG_GS: fprintf(stderr, "%%gs"); break; } return TRUE; +#else + return FALSE; +#endif } /*********************************************************************** @@ -93,6 +99,7 @@ DEBUG_PrintRegister(enum debug_regs reg) */ int DEBUG_GetRegister( enum debug_regs reg ) { +#ifdef __i386__ switch(reg) { case REG_EAX: return EAX_reg(&DEBUG_context); @@ -122,6 +129,7 @@ int DEBUG_GetRegister( enum debug_regs reg ) case REG_IP: return LOWORD(EIP_reg(&DEBUG_context)); case REG_SP: return LOWORD(ESP_reg(&DEBUG_context)); } +#endif return 0; /* should not happen */ } @@ -187,10 +195,9 @@ char *DEBUG_Flags( DWORD flag, char *buf ) */ void DEBUG_InfoRegisters(void) { - char flag[33]; - fprintf(stderr,"Register dump:\n"); +#ifdef __i386__ /* First get the segment registers out of the way */ fprintf( stderr," CS:%04x SS:%04x DS:%04x ES:%04x FS:%04x GS:%04x", (WORD)CS_reg(&DEBUG_context), (WORD)SS_reg(&DEBUG_context), @@ -198,6 +205,8 @@ void DEBUG_InfoRegisters(void) (WORD)FS_reg(&DEBUG_context), (WORD)GS_reg(&DEBUG_context) ); if (dbg_mode == 16) { + char flag[33]; + fprintf( stderr,"\n IP:%04x SP:%04x BP:%04x FLAGS:%04x(%s)\n", LOWORD(EIP_reg(&DEBUG_context)), LOWORD(ESP_reg(&DEBUG_context)), LOWORD(EBP_reg(&DEBUG_context)), LOWORD(EFL_reg(&DEBUG_context)), @@ -209,6 +218,8 @@ void DEBUG_InfoRegisters(void) } else /* 32-bit mode */ { + char flag[33]; + fprintf( stderr, "\n EIP:%08lx ESP:%08lx EBP:%08lx EFLAGS:%08lx(%s)\n", EIP_reg(&DEBUG_context), ESP_reg(&DEBUG_context), EBP_reg(&DEBUG_context), EFL_reg(&DEBUG_context), @@ -219,6 +230,7 @@ void DEBUG_InfoRegisters(void) fprintf( stderr, " ESI:%08lx EDI:%08lx\n", ESI_reg(&DEBUG_context), EDI_reg(&DEBUG_context) ); } +#endif } @@ -230,6 +242,7 @@ void DEBUG_InfoRegisters(void) */ BOOL DEBUG_ValidateRegisters(void) { +#ifdef __i386__ WORD cs, ds; if (ISV86(&DEBUG_context)) return TRUE; @@ -270,4 +283,7 @@ BOOL DEBUG_ValidateRegisters(void) } return TRUE; #undef CHECK_SEG +#else + return TRUE; +#endif } diff --git a/debugger/source.c b/debugger/source.c index fb9dff3559c..05e8c708fb0 100644 --- a/debugger/source.c +++ b/debugger/source.c @@ -430,6 +430,27 @@ DEBUG_List(struct list_id * source1, struct list_id * source2, DBG_ADDR DEBUG_LastDisassemble={NULL,0,0}; +void DEBUG_GetCurrentAddress( DBG_ADDR *addr ) +{ +#ifdef __i386__ + TDB *pTask = (TDB*)GlobalLock16( GetCurrentTask() ); + + addr->type = NULL; + addr->seg = CS_reg(&DEBUG_context); + addr->off = EIP_reg(&DEBUG_context); + + if (ISV86(&DEBUG_context)) addr->seg |= (DWORD)(pTask? pTask->hModule : 0) << 16; + else if (IS_SELECTOR_SYSTEM(addr->seg)) addr->seg = 0; + + GlobalUnlock16( GetCurrentTask() ); +#else + addr->type = NULL; + addr->seg = 0; + addr->off = (DWORD)GET_IP(&DEBUG_context); +#endif +} + + static int _disassemble(DBG_ADDR *addr) { @@ -494,14 +515,8 @@ DEBUG_Disassemble(const DBG_ADDR *xstart,const DBG_ADDR *xend,int offset) if (!xstart && !xend) { last = DEBUG_LastDisassemble; if (!last.seg && !last.off) - { - TDB *pTask = (TDB*)GlobalLock16( GetCurrentTask() ); - last.seg = CS_reg(&DEBUG_context); - last.off = EIP_reg(&DEBUG_context); - if (ISV86(&DEBUG_context)) last.seg |= (DWORD)(pTask?(pTask->hModule):0)<<16; else - if (IS_SELECTOR_SYSTEM(last.seg)) last.seg = 0; - GlobalUnlock16( GetCurrentTask() ); - } + DEBUG_GetCurrentAddress( &last ); + for (i=0;i<offset;i++) if (!_disassemble(&last)) break; memcpy(&DEBUG_LastDisassemble,&last,sizeof(last)); diff --git a/debugger/stack.c b/debugger/stack.c index 1dc44d5d626..4965e1bd073 100644 --- a/debugger/stack.c +++ b/debugger/stack.c @@ -53,6 +53,7 @@ typedef struct */ void DEBUG_InfoStack(void) { +#ifdef __i386__ DBG_ADDR addr; addr.type = NULL; @@ -70,9 +71,10 @@ void DEBUG_InfoStack(void) DEBUG_ExamineMemory( &addr, 24, 'w' ); } fprintf(stderr,"\n"); +#endif } - +#ifdef __i386__ static void DEBUG_ForceFrame(DBG_ADDR *stack, DBG_ADDR *code, int frameno, int bits, int noisy) { int theframe = nframe++; @@ -333,6 +335,9 @@ static void DEBUG_DoBackTrace(int noisy) } if (noisy) fprintf( stderr, "\n" ); } +#endif + + /*********************************************************************** * DEBUG_BackTrace @@ -341,7 +346,9 @@ static void DEBUG_DoBackTrace(int noisy) */ void DEBUG_BackTrace(void) { +#ifdef __i386__ DEBUG_DoBackTrace( TRUE ); +#endif } /*********************************************************************** @@ -351,7 +358,9 @@ void DEBUG_BackTrace(void) */ void DEBUG_SilentBackTrace(void) { +#ifdef __i386__ DEBUG_DoBackTrace( FALSE ); +#endif } int diff --git a/include/debugger.h b/include/debugger.h index b60c4332be2..f79dd2d1748 100644 --- a/include/debugger.h +++ b/include/debugger.h @@ -84,6 +84,8 @@ struct wine_locals { typedef struct wine_locals WineLocals; +#ifdef __i386__ + #define DBG_V86_MODULE(seg) ((seg)>>16) #define IS_SELECTOR_V86(seg) DBG_V86_MODULE(seg) @@ -99,6 +101,13 @@ typedef struct wine_locals WineLocals; (IS_SELECTOR_SYSTEM((addr)->seg) ? (char *)(addr)->off \ : (char *)PTR_SEG_OFF_TO_LIN((addr)->seg,(addr)->off))) +#else /* __i386__ */ + +#define DBG_FIX_ADDR_SEG(addr,default) +#define DBG_ADDR_TO_LIN(addr) ((char *)(addr)->off) + +#endif /* __386__ */ + #define DBG_CHECK_READ_PTR(addr,len) \ (!DEBUG_IsBadReadPtr((addr),(len)) || \ (fprintf(stderr,"*** Invalid address "), \ @@ -313,6 +322,7 @@ extern void DEBUG_AddPath(const char * path); extern void DEBUG_List(struct list_id * line1, struct list_id * line2, int delta); extern void DEBUG_NukePath(void); +extern void DEBUG_GetCurrentAddress( DBG_ADDR * ); extern void DEBUG_Disassemble( const DBG_ADDR *, const DBG_ADDR*, int offset ); /* debugger/dbg.y */ -- GitLab