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 addr
.off
= EBP_reg(DEBUG_context
);
95 FRAME32
*frame
= (FRAME32
*)addr
.off
;
96 if (!DBG_CHECK_READ_PTR( &addr
, sizeof(FRAME32
) )) return;
97 if (!frame
->ip
) break;
106 frames
= (struct bt_info
*) xmalloc(nframe
107 * sizeof(struct bt_info
) );
108 fprintf(stderr
,"%s%d ",(curr_frame
== 0 ? "=>" : " "), frameno
++);
109 addr
.off
= EIP_reg(DEBUG_context
);
110 frames
[0].eip
= addr
.off
;
111 frames
[0].frame
= DEBUG_PrintAddress( &addr
, 32, TRUE
);
112 fprintf( stderr
, "\n" );
113 addr
.off
= EBP_reg(DEBUG_context
);
115 frames
[0].ebp
= addr
.off
;
119 FRAME32
*frame
= (FRAME32
*)addr
.off
;
120 if (!DBG_CHECK_READ_PTR( &addr
, sizeof(FRAME32
) )) return;
121 if (!frame
->ip
) break;
122 fprintf(stderr
,"%s%d ", (frameno
== curr_frame
? "=>" : " "),
124 addr
.off
= frame
->ip
;
125 frames
[frameno
].eip
= addr
.off
;
126 frames
[frameno
].ebp
= frame
->bp
;
127 frames
[frameno
].frame
= DEBUG_PrintAddressAndArgs( &addr
, 32,
130 fprintf( stderr
, "\n" );
131 addr
.off
= frame
->bp
;
134 else /* 16-bit mode */
136 WORD ss
= SS_reg(DEBUG_context
), cs
= CS_reg(DEBUG_context
);
137 if (GET_SEL_FLAGS(ss
) & LDT_FLAGS_32BIT
)
139 fprintf( stderr
, "Not implemented: 32-bit backtrace on a different stack segment.\n" );
142 fprintf( stderr
,"%d ", frameno
++ );
144 addr
.off
= IP_reg(DEBUG_context
);
145 DEBUG_PrintAddress( &addr
, 16, TRUE
);
146 fprintf( stderr
, "\n" );
148 addr
.off
= BP_reg(DEBUG_context
) & ~1;
151 FRAME16
*frame
= (FRAME16
*)DBG_ADDR_TO_LIN(&addr
);
152 if (!DBG_CHECK_READ_PTR( &addr
, sizeof(FRAME16
) )) return;
153 if (!frame
->bp
) break;
154 if (frame
->bp
& 1) cs
= frame
->cs
;
155 fprintf( stderr
,"%d ", frameno
++ );
157 addr
.off
= frame
->ip
;
158 DEBUG_PrintAddress( &addr
, 16, TRUE
);
159 fprintf( stderr
, "\n" );
161 addr
.off
= frame
->bp
& ~1;
164 fprintf( stderr
, "\n" );
167 /***********************************************************************
168 * DEBUG_GetSymbolValue
170 * Get the address of a named symbol from the current stack frame.
172 BOOL32
DEBUG_GetStackSymbolValue( const char * name
, DBG_ADDR
*addr
)
174 struct name_hash
* curr_func
;
178 * If we don't have a valid backtrace, then just return.
185 curr_func
= frames
[curr_frame
].frame
;
188 * If we don't know what the current function is, then we also have
189 * nothing to report here.
191 if( curr_func
== NULL
)
196 for(i
=0; i
< curr_func
->n_locals
; i
++ )
199 * Test the range of validity of the local variable. This
200 * comes up with RBRAC/LBRAC stabs in particular.
202 if( (curr_func
->local_vars
[i
].pc_start
!= 0)
203 && ((frames
[curr_frame
].eip
- curr_func
->addr
.off
)
204 < curr_func
->local_vars
[i
].pc_start
) )
209 if( (curr_func
->local_vars
[i
].pc_end
!= 0)
210 && ((frames
[curr_frame
].eip
- curr_func
->addr
.off
)
211 > curr_func
->local_vars
[i
].pc_end
) )
216 if( strcmp(name
, curr_func
->local_vars
[i
].name
) == 0 )
219 * OK, we found it. Now figure out what to do with this.
221 if( curr_func
->local_vars
[i
].regno
!= 0 )
224 * Register variable. We don't know how to treat
231 addr
->off
= frames
[curr_frame
].ebp
+ curr_func
->local_vars
[i
].offset
;
240 DEBUG_SetFrame(int newframe
)
244 * Nothing for now. Add support later.
247 curr_frame
= newframe
;
253 if( curr_frame
>= nframe
)
255 curr_frame
= nframe
- 1;
265 struct name_hash
* curr_func
;
271 * If we don't have a valid backtrace, then just return.
278 curr_func
= frames
[curr_frame
].frame
;
281 * If we don't know what the current function is, then we also have
282 * nothing to report here.
284 if( curr_func
== NULL
)
289 for(i
=0; i
< curr_func
->n_locals
; i
++ )
292 * Test the range of validity of the local variable. This
293 * comes up with RBRAC/LBRAC stabs in particular.
295 if( (curr_func
->local_vars
[i
].pc_start
!= 0)
296 && ((frames
[curr_frame
].eip
- curr_func
->addr
.off
)
297 < curr_func
->local_vars
[i
].pc_start
) )
302 if( (curr_func
->local_vars
[i
].pc_end
!= 0)
303 && ((frames
[curr_frame
].eip
- curr_func
->addr
.off
)
304 > curr_func
->local_vars
[i
].pc_end
) )
309 if( curr_func
->local_vars
[i
].offset
== 0 )
311 fprintf(stderr
, "%s:%s optimized into register $%s \n",
312 curr_func
->name
, curr_func
->local_vars
[i
].name
,
313 reg_name
[curr_func
->local_vars
[i
].regno
]);
317 ptr
= (unsigned int *) (frames
[curr_frame
].ebp
318 + curr_func
->local_vars
[i
].offset
);
319 fprintf(stderr
, "%s:%s == 0x%8.8x\n",
320 curr_func
->name
, curr_func
->local_vars
[i
].name
,