Alexandre Julliard | ded3038 | 1995-07-06 17:18:27 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Debugger stack handling |
| 3 | * |
| 4 | * Copyright 1995 Alexandre Julliard |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 5 | * Copyright 1996 Eric Youngdale |
Ove Kaaven | b4a5db5 | 1999-05-08 12:38:20 +0000 | [diff] [blame] | 6 | * Copyright 1999 Ove Kåven |
Alexandre Julliard | ded3038 | 1995-07-06 17:18:27 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
Marcus Meissner | b0d52b0 | 1999-02-28 19:59:00 +0000 | [diff] [blame] | 9 | #include "config.h" |
Alexandre Julliard | ded3038 | 1995-07-06 17:18:27 +0000 | [diff] [blame] | 10 | #include <stdio.h> |
Alexandre Julliard | 84c70f5 | 1997-05-09 08:40:27 +0000 | [diff] [blame] | 11 | #include <stdlib.h> |
Alexandre Julliard | ded3038 | 1995-07-06 17:18:27 +0000 | [diff] [blame] | 12 | #include "debugger.h" |
Ove Kaaven | b4a5db5 | 1999-05-08 12:38:20 +0000 | [diff] [blame] | 13 | #include "stackframe.h" |
Alexandre Julliard | ded3038 | 1995-07-06 17:18:27 +0000 | [diff] [blame] | 14 | |
| 15 | |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 16 | /* |
| 17 | * We keep this info for each frame, so that we can |
| 18 | * find local variable information correctly. |
| 19 | */ |
| 20 | struct bt_info |
| 21 | { |
Ove Kaaven | b4a5db5 | 1999-05-08 12:38:20 +0000 | [diff] [blame] | 22 | unsigned int cs; |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 23 | unsigned int eip; |
Ove Kaaven | b4a5db5 | 1999-05-08 12:38:20 +0000 | [diff] [blame] | 24 | unsigned int ss; |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 25 | unsigned int ebp; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 26 | struct symbol_info frame; |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 27 | }; |
| 28 | |
| 29 | static int nframe; |
| 30 | static struct bt_info * frames = NULL; |
| 31 | int curr_frame; |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 32 | |
Alexandre Julliard | ded3038 | 1995-07-06 17:18:27 +0000 | [diff] [blame] | 33 | typedef struct |
| 34 | { |
| 35 | WORD bp; |
| 36 | WORD ip; |
| 37 | WORD cs; |
| 38 | } FRAME16; |
| 39 | |
| 40 | typedef struct |
| 41 | { |
| 42 | DWORD bp; |
| 43 | DWORD ip; |
| 44 | WORD cs; |
| 45 | } FRAME32; |
| 46 | |
| 47 | |
| 48 | |
| 49 | /*********************************************************************** |
| 50 | * DEBUG_InfoStack |
| 51 | * |
| 52 | * Dump the top of the stack |
| 53 | */ |
| 54 | void DEBUG_InfoStack(void) |
| 55 | { |
Patrik Stridvall | 0f8bc5b | 1999-04-22 16:27:50 +0000 | [diff] [blame] | 56 | DBG_ADDR addr; |
| 57 | |
| 58 | addr.type = NULL; |
| 59 | addr.seg = SS_reg(&DEBUG_context); |
| 60 | addr.off = ESP_reg(&DEBUG_context); |
Alexandre Julliard | 808cb04 | 1995-08-17 17:11:36 +0000 | [diff] [blame] | 61 | |
Alexandre Julliard | ded3038 | 1995-07-06 17:18:27 +0000 | [diff] [blame] | 62 | fprintf(stderr,"Stack dump:\n"); |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 63 | if (IS_SELECTOR_32BIT(addr.seg)) |
Alexandre Julliard | 808cb04 | 1995-08-17 17:11:36 +0000 | [diff] [blame] | 64 | { /* 32-bit mode */ |
Alexandre Julliard | d7d4fdf | 1995-12-26 15:05:24 +0000 | [diff] [blame] | 65 | DEBUG_ExamineMemory( &addr, 24, 'x' ); |
Alexandre Julliard | ded3038 | 1995-07-06 17:18:27 +0000 | [diff] [blame] | 66 | } |
| 67 | else /* 16-bit mode */ |
| 68 | { |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 69 | addr.off &= 0xffff; |
Alexandre Julliard | d7d4fdf | 1995-12-26 15:05:24 +0000 | [diff] [blame] | 70 | DEBUG_ExamineMemory( &addr, 24, 'w' ); |
Alexandre Julliard | ded3038 | 1995-07-06 17:18:27 +0000 | [diff] [blame] | 71 | } |
| 72 | fprintf(stderr,"\n"); |
| 73 | } |
| 74 | |
| 75 | |
Ove Kaaven | b4a5db5 | 1999-05-08 12:38:20 +0000 | [diff] [blame] | 76 | static void DEBUG_ForceFrame(DBG_ADDR *stack, DBG_ADDR *code, int frameno, int bits, int noisy) |
| 77 | { |
| 78 | int theframe = nframe++; |
| 79 | frames = (struct bt_info *)DBG_realloc(frames, |
| 80 | nframe*sizeof(struct bt_info)); |
| 81 | if (noisy) |
| 82 | fprintf(stderr,"%s%d ", (theframe == curr_frame ? "=>" : " "), |
| 83 | frameno); |
| 84 | frames[theframe].cs = code->seg; |
| 85 | frames[theframe].eip = code->off; |
| 86 | if (noisy) |
| 87 | frames[theframe].frame = DEBUG_PrintAddressAndArgs( code, bits, |
| 88 | stack->off, TRUE ); |
| 89 | else |
| 90 | DEBUG_FindNearestSymbol( code, TRUE, |
| 91 | &frames[theframe].frame.sym, stack->off, |
| 92 | &frames[theframe].frame.list); |
| 93 | frames[theframe].ss = stack->seg; |
| 94 | frames[theframe].ebp = stack->off; |
| 95 | if (noisy) { |
| 96 | fprintf( stderr, (bits == 16) ? " (bp=%04lx)\n" : " (ebp=%08lx)\n", stack->off ); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | static BOOL DEBUG_Frame16(DBG_ADDR *addr, unsigned int *cs, int frameno, int noisy) |
| 101 | { |
| 102 | unsigned int ss = addr->seg, possible_cs = 0; |
| 103 | FRAME16 *frame = (FRAME16 *)DBG_ADDR_TO_LIN(addr); |
| 104 | int theframe = nframe; |
| 105 | |
Eric Pouech | 99b1513 | 1999-08-21 12:56:15 +0000 | [diff] [blame] | 106 | if (DEBUG_IsBadReadPtr( addr, sizeof(FRAME16) )) { |
| 107 | if (noisy) { |
| 108 | fprintf(stderr,"*** Invalid address "); |
| 109 | DEBUG_PrintAddress(addr, dbg_mode, FALSE); |
| 110 | fprintf(stderr,"\n"); |
| 111 | } |
| 112 | return FALSE; |
| 113 | } |
Ove Kaaven | b4a5db5 | 1999-05-08 12:38:20 +0000 | [diff] [blame] | 114 | if (!frame->bp) return FALSE; |
| 115 | nframe++; |
| 116 | frames = (struct bt_info *)DBG_realloc(frames, |
| 117 | nframe*sizeof(struct bt_info)); |
| 118 | if (noisy) |
| 119 | fprintf(stderr,"%s%d ", (theframe == curr_frame ? "=>" : " "), |
| 120 | frameno); |
| 121 | if (frame->bp & 1) *cs = frame->cs; |
| 122 | else { |
| 123 | /* not explicitly marked as far call, |
| 124 | * but check whether it could be anyway */ |
| 125 | if (((frame->cs&7)==7) && (frame->cs != *cs) && !IS_SELECTOR_FREE(frame->cs)) { |
| 126 | ldt_entry tcs; |
| 127 | LDT_GetEntry( SELECTOR_TO_ENTRY(frame->cs), &tcs ); |
| 128 | if ( tcs.type == SEGMENT_CODE ) { |
| 129 | /* it is very uncommon to push a code segment cs as |
| 130 | * a parameter, so this should work in most cases */ |
| 131 | *cs = possible_cs = frame->cs; |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | frames[theframe].cs = addr->seg = *cs; |
| 136 | frames[theframe].eip = addr->off = frame->ip; |
| 137 | if (noisy) |
| 138 | frames[theframe].frame = DEBUG_PrintAddressAndArgs( addr, 16, |
| 139 | frame->bp, TRUE ); |
| 140 | else |
| 141 | DEBUG_FindNearestSymbol( addr, TRUE, |
| 142 | &frames[theframe].frame.sym, frame->bp, |
| 143 | &frames[theframe].frame.list); |
| 144 | frames[theframe].ss = addr->seg = ss; |
| 145 | frames[theframe].ebp = addr->off = frame->bp & ~1; |
| 146 | if (noisy) { |
| 147 | fprintf( stderr, " (bp=%04lx", addr->off ); |
| 148 | if (possible_cs) { |
| 149 | fprintf( stderr, ", far call assumed" ); |
| 150 | } |
| 151 | fprintf( stderr, ")\n" ); |
| 152 | } |
| 153 | return TRUE; |
| 154 | } |
| 155 | |
| 156 | static BOOL DEBUG_Frame32(DBG_ADDR *addr, unsigned int *cs, int frameno, int noisy) |
| 157 | { |
| 158 | unsigned int ss = addr->seg; |
| 159 | FRAME32 *frame = (FRAME32 *)DBG_ADDR_TO_LIN(addr); |
| 160 | int theframe = nframe; |
| 161 | |
Eric Pouech | 99b1513 | 1999-08-21 12:56:15 +0000 | [diff] [blame] | 162 | if (DEBUG_IsBadReadPtr( addr, sizeof(FRAME32) )) { |
| 163 | if (noisy) { |
| 164 | fprintf(stderr,"*** Invalid address "); |
| 165 | DEBUG_PrintAddress(addr, dbg_mode, FALSE); |
| 166 | fprintf(stderr,"\n"); |
| 167 | } |
| 168 | return FALSE; |
| 169 | } |
Ove Kaaven | b4a5db5 | 1999-05-08 12:38:20 +0000 | [diff] [blame] | 170 | if (!frame->ip) return FALSE; |
| 171 | nframe++; |
| 172 | frames = (struct bt_info *)DBG_realloc(frames, |
| 173 | nframe*sizeof(struct bt_info)); |
| 174 | if (noisy) |
| 175 | fprintf(stderr,"%s%d ", (theframe == curr_frame ? "=>" : " "), |
| 176 | frameno); |
| 177 | frames[theframe].cs = addr->seg = *cs; |
| 178 | frames[theframe].eip = addr->off = frame->ip; |
| 179 | if (noisy) |
| 180 | frames[theframe].frame = DEBUG_PrintAddressAndArgs( addr, 32, |
| 181 | frame->bp, TRUE ); |
| 182 | else |
| 183 | DEBUG_FindNearestSymbol( addr, TRUE, |
| 184 | &frames[theframe].frame.sym, frame->bp, |
| 185 | &frames[theframe].frame.list); |
| 186 | if (noisy) fprintf( stderr, " (ebp=%08lx)\n", frame->bp ); |
| 187 | frames[theframe].ss = addr->seg = ss; |
| 188 | frames[theframe].ebp = frame->bp; |
| 189 | if (addr->off == frame->bp) return FALSE; |
| 190 | addr->off = frame->bp; |
| 191 | return TRUE; |
| 192 | } |
| 193 | |
| 194 | static void DEBUG_DoBackTrace(int noisy) |
| 195 | { |
| 196 | DBG_ADDR addr, sw_addr; |
| 197 | unsigned int ss = SS_reg(&DEBUG_context), cs = CS_reg(&DEBUG_context); |
| 198 | int frameno = 0, is16, ok; |
| 199 | DWORD next_switch, cur_switch; |
| 200 | |
| 201 | if (noisy) fprintf( stderr, "Backtrace:\n" ); |
| 202 | |
| 203 | nframe = 1; |
| 204 | if (frames) DBG_free( frames ); |
| 205 | frames = (struct bt_info *) DBG_alloc( sizeof(struct bt_info) ); |
Ove Kaaven | c6c0483 | 1999-05-09 15:51:43 +0000 | [diff] [blame] | 206 | if (noisy) |
| 207 | fprintf(stderr,"%s%d ",(curr_frame == 0 ? "=>" : " "), frameno); |
Ove Kaaven | b4a5db5 | 1999-05-08 12:38:20 +0000 | [diff] [blame] | 208 | |
| 209 | if (IS_SELECTOR_SYSTEM(ss)) ss = 0; |
| 210 | if (IS_SELECTOR_SYSTEM(cs)) cs = 0; |
| 211 | |
| 212 | /* first stack frame from registers */ |
| 213 | if (IS_SELECTOR_32BIT(ss)) |
| 214 | { |
| 215 | frames[0].cs = addr.seg = cs; |
| 216 | frames[0].eip = addr.off = EIP_reg(&DEBUG_context); |
| 217 | if (noisy) |
| 218 | frames[0].frame = DEBUG_PrintAddress( &addr, 32, TRUE ); |
| 219 | else |
| 220 | DEBUG_FindNearestSymbol( &addr, TRUE, &frames[0].frame.sym, 0, |
| 221 | &frames[0].frame.list); |
| 222 | frames[0].ss = addr.seg = ss; |
| 223 | frames[0].ebp = addr.off = EBP_reg(&DEBUG_context); |
| 224 | if (noisy) fprintf( stderr, " (ebp=%08x)\n", frames[0].ebp ); |
| 225 | is16 = FALSE; |
| 226 | } else { |
| 227 | frames[0].cs = addr.seg = cs; |
Alexandre Julliard | 7d8cfeb | 1999-08-01 14:58:01 +0000 | [diff] [blame] | 228 | frames[0].eip = addr.off = LOWORD(EIP_reg(&DEBUG_context)); |
Ove Kaaven | b4a5db5 | 1999-05-08 12:38:20 +0000 | [diff] [blame] | 229 | if (noisy) |
| 230 | frames[0].frame = DEBUG_PrintAddress( &addr, 16, TRUE ); |
| 231 | else |
| 232 | DEBUG_FindNearestSymbol( &addr, TRUE, &frames[0].frame.sym, 0, |
| 233 | &frames[0].frame.list); |
| 234 | frames[0].ss = addr.seg = ss; |
| 235 | frames[0].ebp = addr.off = BP_reg(&DEBUG_context); |
| 236 | if (noisy) fprintf( stderr, " (bp=%04x)\n", frames[0].ebp ); |
| 237 | is16 = TRUE; |
| 238 | } |
| 239 | |
Alexandre Julliard | 0a860a0 | 1999-06-22 11:43:42 +0000 | [diff] [blame] | 240 | next_switch = NtCurrentTeb()->cur_stack; |
Ove Kaaven | b4a5db5 | 1999-05-08 12:38:20 +0000 | [diff] [blame] | 241 | if (is16) { |
Eric Pouech | cb0f1a9 | 1999-05-24 08:13:49 +0000 | [diff] [blame] | 242 | if (IsBadReadPtr((STACK32FRAME*)next_switch, sizeof(STACK32FRAME))) { |
Eric Pouech | 99b1513 | 1999-08-21 12:56:15 +0000 | [diff] [blame] | 243 | if (noisy) fprintf( stderr, "Bad stack frame %p\n", (STACK32FRAME*)next_switch ); |
Eric Pouech | cb0f1a9 | 1999-05-24 08:13:49 +0000 | [diff] [blame] | 244 | return; |
| 245 | } |
Ove Kaaven | b4a5db5 | 1999-05-08 12:38:20 +0000 | [diff] [blame] | 246 | cur_switch = (DWORD)((STACK32FRAME*)next_switch)->frame16; |
| 247 | sw_addr.seg = SELECTOROF(cur_switch); |
| 248 | sw_addr.off = OFFSETOF(cur_switch); |
| 249 | } else { |
Eric Pouech | cb0f1a9 | 1999-05-24 08:13:49 +0000 | [diff] [blame] | 250 | if (IsBadReadPtr((STACK16FRAME*)PTR_SEG_TO_LIN(next_switch), sizeof(STACK16FRAME))) { |
Eric Pouech | 99b1513 | 1999-08-21 12:56:15 +0000 | [diff] [blame] | 251 | if (noisy) fprintf( stderr, "Bad stack frame %p\n", (STACK16FRAME*)PTR_SEG_TO_LIN(next_switch) ); |
Eric Pouech | cb0f1a9 | 1999-05-24 08:13:49 +0000 | [diff] [blame] | 252 | return; |
| 253 | } |
Ove Kaaven | b4a5db5 | 1999-05-08 12:38:20 +0000 | [diff] [blame] | 254 | cur_switch = (DWORD)((STACK16FRAME*)PTR_SEG_TO_LIN(next_switch))->frame32; |
| 255 | sw_addr.seg = ss; |
| 256 | sw_addr.off = cur_switch; |
| 257 | } |
Ove Kaaven | c6c0483 | 1999-05-09 15:51:43 +0000 | [diff] [blame] | 258 | if (DEBUG_IsBadReadPtr(&sw_addr,1)) { |
| 259 | sw_addr.seg = (DWORD)-1; |
| 260 | sw_addr.off = (DWORD)-1; |
| 261 | } |
Ove Kaaven | b4a5db5 | 1999-05-08 12:38:20 +0000 | [diff] [blame] | 262 | |
| 263 | for (ok = TRUE; ok;) { |
| 264 | if ((frames[frameno].ss == sw_addr.seg) && |
| 265 | (frames[frameno].ebp >= sw_addr.off)) { |
| 266 | /* 16<->32 switch... |
| 267 | * yes, I know this is confusing, it gave me a headache too */ |
| 268 | if (is16) { |
| 269 | STACK32FRAME *frame = (STACK32FRAME*)next_switch; |
Eric Pouech | cb0f1a9 | 1999-05-24 08:13:49 +0000 | [diff] [blame] | 270 | DBG_ADDR code; |
| 271 | |
| 272 | if (IsBadReadPtr((STACK32FRAME*)next_switch, sizeof(STACK32FRAME))) { |
Eric Pouech | 99b1513 | 1999-08-21 12:56:15 +0000 | [diff] [blame] | 273 | if (noisy) fprintf( stderr, "Bad stack frame %p\n", (STACK32FRAME*)next_switch ); |
Eric Pouech | cb0f1a9 | 1999-05-24 08:13:49 +0000 | [diff] [blame] | 274 | return; |
| 275 | } |
| 276 | code.type = NULL; |
| 277 | code.seg = 0; |
| 278 | code.off = frame->retaddr; |
Ove Kaaven | b4a5db5 | 1999-05-08 12:38:20 +0000 | [diff] [blame] | 279 | |
| 280 | cs = 0; |
| 281 | addr.seg = 0; |
| 282 | addr.off = frame->ebp; |
| 283 | DEBUG_ForceFrame( &addr, &code, ++frameno, 32, noisy ); |
| 284 | |
| 285 | next_switch = cur_switch; |
Eric Pouech | cb0f1a9 | 1999-05-24 08:13:49 +0000 | [diff] [blame] | 286 | if (IsBadReadPtr((STACK16FRAME*)PTR_SEG_TO_LIN(next_switch), sizeof(STACK16FRAME))) { |
Eric Pouech | 99b1513 | 1999-08-21 12:56:15 +0000 | [diff] [blame] | 287 | if (noisy) fprintf( stderr, "Bad stack frame %p\n", (STACK16FRAME*)PTR_SEG_TO_LIN(next_switch) ); |
Eric Pouech | cb0f1a9 | 1999-05-24 08:13:49 +0000 | [diff] [blame] | 288 | return; |
| 289 | } |
Ove Kaaven | b4a5db5 | 1999-05-08 12:38:20 +0000 | [diff] [blame] | 290 | cur_switch = (DWORD)((STACK16FRAME*)PTR_SEG_TO_LIN(next_switch))->frame32; |
| 291 | sw_addr.seg = 0; |
| 292 | sw_addr.off = cur_switch; |
| 293 | |
| 294 | is16 = FALSE; |
| 295 | } else { |
| 296 | STACK16FRAME *frame = (STACK16FRAME*)PTR_SEG_TO_LIN(next_switch); |
Eric Pouech | cb0f1a9 | 1999-05-24 08:13:49 +0000 | [diff] [blame] | 297 | DBG_ADDR code; |
| 298 | |
| 299 | if (IsBadReadPtr((STACK16FRAME*)PTR_SEG_TO_LIN(next_switch), sizeof(STACK16FRAME))) { |
Eric Pouech | 99b1513 | 1999-08-21 12:56:15 +0000 | [diff] [blame] | 300 | if (noisy) fprintf( stderr, "Bad stack frame %p\n", (STACK16FRAME*)PTR_SEG_TO_LIN(next_switch) ); |
Eric Pouech | cb0f1a9 | 1999-05-24 08:13:49 +0000 | [diff] [blame] | 301 | return; |
| 302 | } |
| 303 | |
| 304 | code.type = NULL; |
| 305 | code.seg = frame->cs; |
| 306 | code.off = frame->ip; |
Ove Kaaven | b4a5db5 | 1999-05-08 12:38:20 +0000 | [diff] [blame] | 307 | |
| 308 | cs = frame->cs; |
| 309 | addr.seg = SELECTOROF(next_switch); |
| 310 | addr.off = frame->bp; |
| 311 | DEBUG_ForceFrame( &addr, &code, ++frameno, 16, noisy ); |
| 312 | |
| 313 | next_switch = cur_switch; |
Eric Pouech | cb0f1a9 | 1999-05-24 08:13:49 +0000 | [diff] [blame] | 314 | if (IsBadReadPtr((STACK32FRAME*)next_switch, sizeof(STACK32FRAME))) { |
Eric Pouech | 99b1513 | 1999-08-21 12:56:15 +0000 | [diff] [blame] | 315 | if (noisy) fprintf( stderr, "Bad stack frame %p\n", (STACK32FRAME*)next_switch ); |
Eric Pouech | cb0f1a9 | 1999-05-24 08:13:49 +0000 | [diff] [blame] | 316 | return; |
| 317 | } |
Ove Kaaven | b4a5db5 | 1999-05-08 12:38:20 +0000 | [diff] [blame] | 318 | cur_switch = (DWORD)((STACK32FRAME*)next_switch)->frame16; |
| 319 | sw_addr.seg = SELECTOROF(cur_switch); |
| 320 | sw_addr.off = OFFSETOF(cur_switch); |
| 321 | |
| 322 | is16 = TRUE; |
| 323 | } |
Ove Kaaven | c6c0483 | 1999-05-09 15:51:43 +0000 | [diff] [blame] | 324 | if (DEBUG_IsBadReadPtr(&sw_addr,1)) { |
| 325 | sw_addr.seg = (DWORD)-1; |
| 326 | sw_addr.off = (DWORD)-1; |
| 327 | } |
Ove Kaaven | b4a5db5 | 1999-05-08 12:38:20 +0000 | [diff] [blame] | 328 | } else { |
| 329 | /* ordinary stack frame */ |
| 330 | ok = is16 ? DEBUG_Frame16( &addr, &cs, ++frameno, noisy) |
| 331 | : DEBUG_Frame32( &addr, &cs, ++frameno, noisy); |
| 332 | } |
| 333 | } |
| 334 | if (noisy) fprintf( stderr, "\n" ); |
| 335 | } |
| 336 | |
Alexandre Julliard | ded3038 | 1995-07-06 17:18:27 +0000 | [diff] [blame] | 337 | /*********************************************************************** |
| 338 | * DEBUG_BackTrace |
| 339 | * |
| 340 | * Display a stack back-trace. |
| 341 | */ |
| 342 | void DEBUG_BackTrace(void) |
| 343 | { |
Ove Kaaven | b4a5db5 | 1999-05-08 12:38:20 +0000 | [diff] [blame] | 344 | DEBUG_DoBackTrace( TRUE ); |
Alexandre Julliard | ded3038 | 1995-07-06 17:18:27 +0000 | [diff] [blame] | 345 | } |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 346 | |
| 347 | /*********************************************************************** |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 348 | * DEBUG_SilentBackTrace |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 349 | * |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 350 | * Display a stack back-trace. |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 351 | */ |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 352 | void DEBUG_SilentBackTrace(void) |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 353 | { |
Ove Kaaven | b4a5db5 | 1999-05-08 12:38:20 +0000 | [diff] [blame] | 354 | DEBUG_DoBackTrace( FALSE ); |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | int |
| 358 | DEBUG_SetFrame(int newframe) |
| 359 | { |
| 360 | int rtn = FALSE; |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 361 | |
| 362 | curr_frame = newframe; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 363 | |
| 364 | if( curr_frame >= nframe ) |
| 365 | { |
| 366 | curr_frame = nframe - 1; |
| 367 | } |
| 368 | |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 369 | if( curr_frame < 0 ) |
| 370 | { |
| 371 | curr_frame = 0; |
| 372 | } |
| 373 | |
Eric Pouech | 761e314 | 1999-02-20 16:40:47 +0000 | [diff] [blame] | 374 | if( frames && frames[curr_frame].frame.list.sourcefile != NULL ) |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 375 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 376 | DEBUG_List(&frames[curr_frame].frame.list, NULL, 0); |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | rtn = TRUE; |
| 380 | return (rtn); |
| 381 | } |
| 382 | |
| 383 | int |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 384 | DEBUG_GetCurrentFrame(struct name_hash ** name, unsigned int * eip, |
| 385 | unsigned int * ebp) |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 386 | { |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 387 | /* |
| 388 | * If we don't have a valid backtrace, then just return. |
| 389 | */ |
| 390 | if( frames == NULL ) |
| 391 | { |
| 392 | return FALSE; |
| 393 | } |
| 394 | |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 395 | /* |
| 396 | * If we don't know what the current function is, then we also have |
| 397 | * nothing to report here. |
| 398 | */ |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 399 | if( frames[curr_frame].frame.sym == NULL ) |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 400 | { |
| 401 | return FALSE; |
| 402 | } |
| 403 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 404 | *name = frames[curr_frame].frame.sym; |
| 405 | *eip = frames[curr_frame].eip; |
| 406 | *ebp = frames[curr_frame].ebp; |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 407 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 408 | return TRUE; |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 409 | } |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 410 | |