2 * Debugger stack handling
4 * Copyright 1995 Alexandre Julliard
5 * Copyright 1996 Eric Youngdale
15 * We keep this info for each frame, so that we can
16 * find local variable information correctly.
23 struct symbol_info frame
;
27 static struct bt_info
* frames
= NULL
;
46 /***********************************************************************
49 * Dump the top of the stack
51 void DEBUG_InfoStack(void)
56 addr
.seg
= SS_reg(&DEBUG_context
);
57 addr
.off
= ESP_reg(&DEBUG_context
);
59 fprintf(stderr
,"Stack dump:\n");
60 if (IS_SELECTOR_32BIT(addr
.seg
))
62 DEBUG_ExamineMemory( &addr
, 24, 'x' );
64 else /* 16-bit mode */
67 DEBUG_ExamineMemory( &addr
, 24, 'w' );
73 /***********************************************************************
76 * Display a stack back-trace.
78 void DEBUG_BackTrace(void)
83 fprintf(stderr
,"Backtrace:\n");
84 if (IS_SELECTOR_SYSTEM(SS_reg(&DEBUG_context
))) /* system stack */
87 if (frames
) DBG_free( frames
);
88 frames
= (struct bt_info
*) DBG_alloc( sizeof(struct bt_info
) );
89 fprintf(stderr
,"%s%d ",(curr_frame
== 0 ? "=>" : " "), frameno
++);
92 addr
.off
= EIP_reg(&DEBUG_context
);
93 frames
[0].eip
= addr
.off
;
94 frames
[0].frame
= DEBUG_PrintAddress( &addr
, 32, TRUE
);
95 fprintf( stderr
, "\n" );
96 frames
[0].ebp
= addr
.off
= EBP_reg(&DEBUG_context
);
100 FRAME32
*frame
= (FRAME32
*)addr
.off
;
101 if (!DBG_CHECK_READ_PTR( &addr
, sizeof(FRAME32
) )) return;
102 if (!frame
->ip
) break;
104 frames
= (struct bt_info
*)DBG_realloc(frames
,
105 nframe
*sizeof(struct bt_info
));
106 fprintf(stderr
,"%s%d ", (frameno
== curr_frame
? "=>" : " "),
108 addr
.off
= frame
->ip
;
109 frames
[frameno
].eip
= addr
.off
;
110 frames
[frameno
].ebp
= frame
->bp
;
111 frames
[frameno
].frame
= DEBUG_PrintAddressAndArgs( &addr
, 32,
114 fprintf( stderr
, "\n" );
115 if (addr
.off
== frame
->bp
) break;
116 addr
.off
= frame
->bp
;
119 else /* 16-bit mode */
121 WORD ss
= SS_reg(&DEBUG_context
), cs
= CS_reg(&DEBUG_context
);
122 if (GET_SEL_FLAGS(ss
) & LDT_FLAGS_32BIT
)
124 fprintf( stderr
, "Not implemented: 32-bit backtrace on a different stack segment.\n" );
127 fprintf( stderr
,"%d ", frameno
++ );
129 addr
.off
= IP_reg(&DEBUG_context
);
130 DEBUG_PrintAddress( &addr
, 16, TRUE
);
131 fprintf( stderr
, "\n" );
133 addr
.off
= BP_reg(&DEBUG_context
) & ~1;
136 FRAME16
*frame
= (FRAME16
*)DBG_ADDR_TO_LIN(&addr
);
137 if (!DBG_CHECK_READ_PTR( &addr
, sizeof(FRAME16
) )) return;
138 if (!frame
->bp
) break;
139 if (frame
->bp
& 1) cs
= frame
->cs
;
140 fprintf( stderr
,"%d ", frameno
++ );
142 addr
.off
= frame
->ip
;
143 DEBUG_PrintAddress( &addr
, 16, TRUE
);
144 fprintf( stderr
, "\n" );
146 addr
.off
= frame
->bp
& ~1;
149 fprintf( stderr
, "\n" );
152 /***********************************************************************
153 * DEBUG_SilentBackTrace
155 * Display a stack back-trace.
157 void DEBUG_SilentBackTrace(void)
163 if (frames
) DBG_free( frames
);
164 frames
= (struct bt_info
*) DBG_alloc( sizeof(struct bt_info
) );
165 if (IS_SELECTOR_SYSTEM(SS_reg(&DEBUG_context
))) /* system stack */
168 addr
.off
= EIP_reg(&DEBUG_context
);
169 frames
[0].eip
= addr
.off
;
170 DEBUG_FindNearestSymbol( &addr
, TRUE
, &frames
[0].frame
.sym
, 0,
171 &frames
[0].frame
.list
);
172 frames
[0].ebp
= addr
.off
= EBP_reg(&DEBUG_context
);
177 FRAME32
*frame
= (FRAME32
*)addr
.off
;
178 if (!DBG_CHECK_READ_PTR( &addr
, sizeof(FRAME32
) )) return;
179 if (!frame
->ip
) break;
181 frames
= (struct bt_info
*)DBG_realloc(frames
,
182 nframe
*sizeof(struct bt_info
));
183 addr
.off
= frame
->ip
;
184 frames
[frameno
].eip
= addr
.off
;
185 frames
[frameno
].ebp
= frame
->bp
;
186 DEBUG_FindNearestSymbol( &addr
, TRUE
,
187 &frames
[frameno
].frame
.sym
, frame
->bp
,
188 &frames
[frameno
].frame
.list
);
190 addr
.off
= frame
->bp
;
193 else /* 16-bit mode */
196 * Not implemented here. I am not entirely sure how best to handle
203 DEBUG_SetFrame(int newframe
)
207 curr_frame
= newframe
;
209 if( curr_frame
>= nframe
)
211 curr_frame
= nframe
- 1;
219 if( frames
&& frames
[curr_frame
].frame
.list
.sourcefile
!= NULL
)
221 DEBUG_List(&frames
[curr_frame
].frame
.list
, NULL
, 0);
229 DEBUG_GetCurrentFrame(struct name_hash
** name
, unsigned int * eip
,
233 * If we don't have a valid backtrace, then just return.
241 * If we don't know what the current function is, then we also have
242 * nothing to report here.
244 if( frames
[curr_frame
].frame
.sym
== NULL
)
249 *name
= frames
[curr_frame
].frame
.sym
;
250 *eip
= frames
[curr_frame
].eip
;
251 *ebp
= frames
[curr_frame
].ebp
;