2 * Debugger register handling
4 * Copyright 1995 Alexandre Julliard
10 SIGCONTEXT
*DEBUG_context
;
12 /***********************************************************************
15 * Set a register value.
17 void DEBUG_SetRegister( enum debug_regs reg
, int val
)
21 case REG_EAX
: EAX_reg(DEBUG_context
) = val
; break;
22 case REG_EBX
: EBX_reg(DEBUG_context
) = val
; break;
23 case REG_ECX
: ECX_reg(DEBUG_context
) = val
; break;
24 case REG_EDX
: EDX_reg(DEBUG_context
) = val
; break;
25 case REG_ESI
: ESI_reg(DEBUG_context
) = val
; break;
26 case REG_EDI
: EDI_reg(DEBUG_context
) = val
; break;
27 case REG_EBP
: EBP_reg(DEBUG_context
) = val
; break;
28 case REG_EFL
: EFL_reg(DEBUG_context
) = val
; break;
29 case REG_EIP
: EIP_reg(DEBUG_context
) = val
; break;
30 case REG_ESP
: ESP_reg(DEBUG_context
) = val
; break;
31 case REG_AX
: AX_reg(DEBUG_context
) = val
; break;
32 case REG_BX
: BX_reg(DEBUG_context
) = val
; break;
33 case REG_CX
: CX_reg(DEBUG_context
) = val
; break;
34 case REG_DX
: DX_reg(DEBUG_context
) = val
; break;
35 case REG_SI
: SI_reg(DEBUG_context
) = val
; break;
36 case REG_DI
: DI_reg(DEBUG_context
) = val
; break;
37 case REG_BP
: BP_reg(DEBUG_context
) = val
; break;
38 case REG_FL
: FL_reg(DEBUG_context
) = val
; break;
39 case REG_IP
: IP_reg(DEBUG_context
) = val
; break;
40 case REG_SP
: SP_reg(DEBUG_context
) = val
; break;
41 case REG_CS
: CS_reg(DEBUG_context
) = val
; break;
42 case REG_DS
: DS_reg(DEBUG_context
) = val
; break;
43 case REG_ES
: ES_reg(DEBUG_context
) = val
; break;
44 case REG_SS
: SS_reg(DEBUG_context
) = val
; break;
46 case REG_FS
: FS_reg(DEBUG_context
) = val
; break;
49 fprintf( stderr
, "Register %%fs not supported on this system\n" );
53 case REG_GS
: GS_reg(DEBUG_context
) = val
; break;
56 fprintf( stderr
, "Register %%gs not supported on this system\n" );
63 /***********************************************************************
66 * Get a register value.
68 int DEBUG_GetRegister( enum debug_regs reg
)
72 case REG_EAX
: return EAX_reg(DEBUG_context
);
73 case REG_EBX
: return EBX_reg(DEBUG_context
);
74 case REG_ECX
: return ECX_reg(DEBUG_context
);
75 case REG_EDX
: return EDX_reg(DEBUG_context
);
76 case REG_ESI
: return ESI_reg(DEBUG_context
);
77 case REG_EDI
: return EDI_reg(DEBUG_context
);
78 case REG_EBP
: return EBP_reg(DEBUG_context
);
79 case REG_EFL
: return EFL_reg(DEBUG_context
);
80 case REG_EIP
: return EIP_reg(DEBUG_context
);
81 case REG_ESP
: return ESP_reg(DEBUG_context
);
82 case REG_AX
: return AX_reg(DEBUG_context
);
83 case REG_BX
: return BX_reg(DEBUG_context
);
84 case REG_CX
: return CX_reg(DEBUG_context
);
85 case REG_DX
: return DX_reg(DEBUG_context
);
86 case REG_SI
: return SI_reg(DEBUG_context
);
87 case REG_DI
: return DI_reg(DEBUG_context
);
88 case REG_BP
: return BP_reg(DEBUG_context
);
89 case REG_FL
: return FL_reg(DEBUG_context
);
90 case REG_IP
: return IP_reg(DEBUG_context
);
91 case REG_SP
: return SP_reg(DEBUG_context
);
92 case REG_CS
: return CS_reg(DEBUG_context
);
93 case REG_DS
: return DS_reg(DEBUG_context
);
94 case REG_ES
: return ES_reg(DEBUG_context
);
95 case REG_SS
: return SS_reg(DEBUG_context
);
97 case REG_FS
: return FS_reg(DEBUG_context
);
100 fprintf( stderr
, "Register %%fs not supported on this system\n" );
104 case REG_GS
: return GS_reg(DEBUG_context
);
107 fprintf( stderr
, "Register %%gs not supported on this system\n" );
111 return 0; /* should not happen */
116 /***********************************************************************
117 * DEBUG_InfoRegisters
119 * Display registers information.
121 void DEBUG_InfoRegisters(void)
123 fprintf(stderr
,"Register dump:\n");
125 /* First get the segment registers out of the way */
126 fprintf( stderr
," CS:%04x SS:%04x DS:%04x ES:%04x",
127 CS_reg(DEBUG_context
), SS_reg(DEBUG_context
),
128 DS_reg(DEBUG_context
), ES_reg(DEBUG_context
) );
130 fprintf( stderr
, " FS:%04x", FS_reg(DEBUG_context
) );
133 fprintf( stderr
, " GS:%04x", GS_reg(DEBUG_context
) );
137 fprintf( stderr
,"\n IP:%04x SP:%04x BP:%04x FLAGS:%04x\n",
138 IP_reg(DEBUG_context
), SP_reg(DEBUG_context
),
139 BP_reg(DEBUG_context
), FL_reg(DEBUG_context
) );
140 fprintf( stderr
," AX:%04x BX:%04x CX:%04x DX:%04x SI:%04x DI:%04x\n",
141 AX_reg(DEBUG_context
), BX_reg(DEBUG_context
),
142 CX_reg(DEBUG_context
), DX_reg(DEBUG_context
),
143 SI_reg(DEBUG_context
), DI_reg(DEBUG_context
) );
145 else /* 32-bit mode */
147 fprintf( stderr
, "\n EIP:%08lx ESP:%08lx EBP:%08lx EFLAGS:%08lx\n",
148 EIP_reg(DEBUG_context
), ESP_reg(DEBUG_context
),
149 EBP_reg(DEBUG_context
), EFL_reg(DEBUG_context
) );
150 fprintf( stderr
, " EAX:%08lx EBX:%08lx ECX:%08lx EDX:%08lx\n",
151 EAX_reg(DEBUG_context
), EBX_reg(DEBUG_context
),
152 ECX_reg(DEBUG_context
), EDX_reg(DEBUG_context
) );
153 fprintf( stderr
, " ESI:%08lx EDI:%08lx\n",
154 ESI_reg(DEBUG_context
), EDI_reg(DEBUG_context
) );
159 /***********************************************************************
160 * DEBUG_ValidateRegisters
162 * Make sure all registers have a correct value for returning from
163 * the signal handler.
165 BOOL32
DEBUG_ValidateRegisters(void)
167 /* Check that a selector is a valid ring-3 LDT selector, or a NULL selector */
168 #define CHECK_SEG(seg,name) \
169 if (((seg) & ~3) && \
170 ((((seg) & 7) != 7) || IS_LDT_ENTRY_FREE(SELECTOR_TO_ENTRY(seg)))) \
172 fprintf( stderr, "*** Invalid value for %s register: %04x\n", \
177 if (CS_reg(DEBUG_context
) != WINE_CODE_SELECTOR
)
178 CHECK_SEG( CS_reg(DEBUG_context
), "CS" );
179 if (SS_reg(DEBUG_context
) != WINE_DATA_SELECTOR
)
180 CHECK_SEG( SS_reg(DEBUG_context
), "SS" );
181 if (DS_reg(DEBUG_context
) != WINE_DATA_SELECTOR
)
182 CHECK_SEG( DS_reg(DEBUG_context
), "DS" );
183 if (ES_reg(DEBUG_context
) != WINE_DATA_SELECTOR
)
184 CHECK_SEG( ES_reg(DEBUG_context
), "ES" );
186 if (FS_reg(DEBUG_context
) != WINE_DATA_SELECTOR
)
187 CHECK_SEG( FS_reg(DEBUG_context
), "FS" );
190 if (GS_reg(DEBUG_context
) != WINE_DATA_SELECTOR
)
191 CHECK_SEG( GS_reg(DEBUG_context
), "GS" );
194 /* Check that CS and SS are not NULL */
196 if (!(CS_reg(DEBUG_context
) & ~3))
198 fprintf( stderr
, "*** Invalid value for CS register: %04x\n",
199 CS_reg(DEBUG_context
) );
202 if (!(SS_reg(DEBUG_context
) & ~3))
204 fprintf( stderr
, "*** Invalid value for SS register: %04x\n",
205 SS_reg(DEBUG_context
) );