2 * Debugger stack handling
4 * Copyright 1995 Alexandre Julliard
5 * Copyright 1996 Eric Youngdale
16 * We keep this info for each frame, so that we can
17 * find local variable information correctly.
23 struct name_hash * frame;
27 static struct bt_info * frames = NULL;
29 static char * reg_name[] =
31 "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi"
50 /***********************************************************************
53 * Dump the top of the stack
55 void DEBUG_InfoStack(void)
59 fprintf(stderr,"Stack dump:\n");
60 if ((SS_reg(&DEBUG_context) == WINE_DATA_SELECTOR) ||
61 (GET_SEL_FLAGS(SS_reg(&DEBUG_context)) & LDT_FLAGS_32BIT))
64 addr.off = ESP_reg(&DEBUG_context);
65 DEBUG_ExamineMemory( &addr, 24, 'x' );
67 else /* 16-bit mode */
69 addr.seg = SS_reg(&DEBUG_context);
70 addr.off = SP_reg(&DEBUG_context);
71 DEBUG_ExamineMemory( &addr, 24, 'w' );
77 /***********************************************************************
80 * Display a stack back-trace.
82 void DEBUG_BackTrace(void)
87 fprintf(stderr,"Backtrace:\n");
88 if (SS_reg(&DEBUG_context) == WINE_DATA_SELECTOR) /* 32-bit mode */
91 if (frames) free( frames );
92 frames = (struct bt_info *) xmalloc( sizeof(struct bt_info) );
93 fprintf(stderr,"%s%d ",(curr_frame == 0 ? "=>" : " "), frameno++);
96 addr.off = EIP_reg(&DEBUG_context);
97 frames[0].eip = addr.off;
98 frames[0].frame = DEBUG_PrintAddress( &addr, 32, TRUE );
99 fprintf( stderr, "\n" );
100 frames[0].ebp = addr.off = EBP_reg(&DEBUG_context);
104 FRAME32 *frame = (FRAME32 *)addr.off;
105 if (!DBG_CHECK_READ_PTR( &addr, sizeof(FRAME32) )) return;
106 if (!frame->ip) break;
108 frames = (struct bt_info *)xrealloc(frames,
109 nframe*sizeof(struct bt_info));
110 fprintf(stderr,"%s%d ", (frameno == curr_frame ? "=>" : " "),
112 addr.off = frame->ip;
113 frames[frameno].eip = addr.off;
114 frames[frameno].ebp = frame->bp;
115 frames[frameno].frame = DEBUG_PrintAddressAndArgs( &addr, 32,
118 fprintf( stderr, "\n" );
119 addr.off = frame->bp;
122 else /* 16-bit mode */
124 WORD ss = SS_reg(&DEBUG_context), cs = CS_reg(&DEBUG_context);
125 if (GET_SEL_FLAGS(ss) & LDT_FLAGS_32BIT)
127 fprintf( stderr, "Not implemented: 32-bit backtrace on a different stack segment.\n" );
130 fprintf( stderr,"%d ", frameno++ );
132 addr.off = IP_reg(&DEBUG_context);
133 DEBUG_PrintAddress( &addr, 16, TRUE );
134 fprintf( stderr, "\n" );
136 addr.off = BP_reg(&DEBUG_context) & ~1;
139 FRAME16 *frame = (FRAME16 *)DBG_ADDR_TO_LIN(&addr);
140 if (!DBG_CHECK_READ_PTR( &addr, sizeof(FRAME16) )) return;
141 if (!frame->bp) break;
142 if (frame->bp & 1) cs = frame->cs;
143 fprintf( stderr,"%d ", frameno++ );
145 addr.off = frame->ip;
146 DEBUG_PrintAddress( &addr, 16, TRUE );
147 fprintf( stderr, "\n" );
149 addr.off = frame->bp & ~1;
152 fprintf( stderr, "\n" );
155 /***********************************************************************
156 * DEBUG_GetSymbolValue
158 * Get the address of a named symbol from the current stack frame.
160 BOOL32 DEBUG_GetStackSymbolValue( const char * name, DBG_ADDR *addr )
162 struct name_hash * curr_func;
166 * If we don't have a valid backtrace, then just return.
173 curr_func = frames[curr_frame].frame;
176 * If we don't know what the current function is, then we also have
177 * nothing to report here.
179 if( curr_func == NULL )
184 for(i=0; i < curr_func->n_locals; i++ )
187 * Test the range of validity of the local variable. This
188 * comes up with RBRAC/LBRAC stabs in particular.
190 if( (curr_func->local_vars[i].pc_start != 0)
191 && ((frames[curr_frame].eip - curr_func->addr.off)
192 < curr_func->local_vars[i].pc_start) )
197 if( (curr_func->local_vars[i].pc_end != 0)
198 && ((frames[curr_frame].eip - curr_func->addr.off)
199 > curr_func->local_vars[i].pc_end) )
204 if( strcmp(name, curr_func->local_vars[i].name) == 0 )
207 * OK, we found it. Now figure out what to do with this.
209 if( curr_func->local_vars[i].regno != 0 )
212 * Register variable. We don't know how to treat
219 addr->off = frames[curr_frame].ebp + curr_func->local_vars[i].offset;
228 DEBUG_SetFrame(int newframe)
232 * Nothing for now. Add support later.
235 curr_frame = newframe;
241 if( curr_frame >= nframe )
243 curr_frame = nframe - 1;
253 struct name_hash * curr_func;
259 * If we don't have a valid backtrace, then just return.
266 curr_func = frames[curr_frame].frame;
269 * If we don't know what the current function is, then we also have
270 * nothing to report here.
272 if( curr_func == NULL )
277 for(i=0; i < curr_func->n_locals; i++ )
280 * Test the range of validity of the local variable. This
281 * comes up with RBRAC/LBRAC stabs in particular.
283 if( (curr_func->local_vars[i].pc_start != 0)
284 && ((frames[curr_frame].eip - curr_func->addr.off)
285 < curr_func->local_vars[i].pc_start) )
290 if( (curr_func->local_vars[i].pc_end != 0)
291 && ((frames[curr_frame].eip - curr_func->addr.off)
292 > curr_func->local_vars[i].pc_end) )
297 if( curr_func->local_vars[i].offset == 0 )
299 fprintf(stderr, "%s:%s optimized into register $%s \n",
300 curr_func->name, curr_func->local_vars[i].name,
301 reg_name[curr_func->local_vars[i].regno]);
305 ptr = (unsigned int *) (frames[curr_frame].ebp
306 + curr_func->local_vars[i].offset);
307 fprintf(stderr, "%s:%s == 0x%8.8x\n",
308 curr_func->name, curr_func->local_vars[i].name,