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.
24 struct symbol_info frame
;
28 static struct bt_info
* frames
= NULL
;
47 /***********************************************************************
50 * Dump the top of the stack
52 void DEBUG_InfoStack(void)
54 DBG_ADDR addr
= { NULL
, SS_reg(&DEBUG_context
), ESP_reg(&DEBUG_context
) };
56 fprintf(stderr
,"Stack dump:\n");
57 if (IS_SELECTOR_32BIT(addr
.seg
))
59 DEBUG_ExamineMemory( &addr
, 24, 'x' );
61 else /* 16-bit mode */
64 DEBUG_ExamineMemory( &addr
, 24, 'w' );
70 /***********************************************************************
73 * Display a stack back-trace.
75 void DEBUG_BackTrace(void)
80 fprintf(stderr
,"Backtrace:\n");
81 if (IS_SELECTOR_SYSTEM(SS_reg(&DEBUG_context
))) /* system stack */
84 if (frames
) free( frames
);
85 frames
= (struct bt_info
*) xmalloc( sizeof(struct bt_info
) );
86 fprintf(stderr
,"%s%d ",(curr_frame
== 0 ? "=>" : " "), frameno
++);
89 addr
.off
= EIP_reg(&DEBUG_context
);
90 frames
[0].eip
= addr
.off
;
91 frames
[0].frame
= DEBUG_PrintAddress( &addr
, 32, TRUE
);
92 fprintf( stderr
, "\n" );
93 frames
[0].ebp
= addr
.off
= EBP_reg(&DEBUG_context
);
97 FRAME32
*frame
= (FRAME32
*)addr
.off
;
98 if (!DBG_CHECK_READ_PTR( &addr
, sizeof(FRAME32
) )) return;
99 if (!frame
->ip
) break;
101 frames
= (struct bt_info
*)xrealloc(frames
,
102 nframe
*sizeof(struct bt_info
));
103 fprintf(stderr
,"%s%d ", (frameno
== curr_frame
? "=>" : " "),
105 addr
.off
= frame
->ip
;
106 frames
[frameno
].eip
= addr
.off
;
107 frames
[frameno
].ebp
= frame
->bp
;
108 frames
[frameno
].frame
= DEBUG_PrintAddressAndArgs( &addr
, 32,
111 fprintf( stderr
, "\n" );
112 if (addr
.off
== frame
->bp
) break;
113 addr
.off
= frame
->bp
;
116 else /* 16-bit mode */
118 WORD ss
= SS_reg(&DEBUG_context
), cs
= CS_reg(&DEBUG_context
);
119 if (GET_SEL_FLAGS(ss
) & LDT_FLAGS_32BIT
)
121 fprintf( stderr
, "Not implemented: 32-bit backtrace on a different stack segment.\n" );
124 fprintf( stderr
,"%d ", frameno
++ );
126 addr
.off
= IP_reg(&DEBUG_context
);
127 DEBUG_PrintAddress( &addr
, 16, TRUE
);
128 fprintf( stderr
, "\n" );
130 addr
.off
= BP_reg(&DEBUG_context
) & ~1;
133 FRAME16
*frame
= (FRAME16
*)DBG_ADDR_TO_LIN(&addr
);
134 if (!DBG_CHECK_READ_PTR( &addr
, sizeof(FRAME16
) )) return;
135 if (!frame
->bp
) break;
136 if (frame
->bp
& 1) cs
= frame
->cs
;
137 fprintf( stderr
,"%d ", frameno
++ );
139 addr
.off
= frame
->ip
;
140 DEBUG_PrintAddress( &addr
, 16, TRUE
);
141 fprintf( stderr
, "\n" );
143 addr
.off
= frame
->bp
& ~1;
146 fprintf( stderr
, "\n" );
149 /***********************************************************************
150 * DEBUG_SilentBackTrace
152 * Display a stack back-trace.
154 void DEBUG_SilentBackTrace(void)
160 if (frames
) free( frames
);
161 frames
= (struct bt_info
*) xmalloc( sizeof(struct bt_info
) );
162 if (IS_SELECTOR_SYSTEM(SS_reg(&DEBUG_context
))) /* system stack */
165 addr
.off
= EIP_reg(&DEBUG_context
);
166 frames
[0].eip
= addr
.off
;
167 DEBUG_FindNearestSymbol( &addr
, TRUE
, &frames
[0].frame
.sym
, 0,
168 &frames
[0].frame
.list
);
169 frames
[0].ebp
= addr
.off
= EBP_reg(&DEBUG_context
);
174 FRAME32
*frame
= (FRAME32
*)addr
.off
;
175 if (!DBG_CHECK_READ_PTR( &addr
, sizeof(FRAME32
) )) return;
176 if (!frame
->ip
) break;
178 frames
= (struct bt_info
*)xrealloc(frames
,
179 nframe
*sizeof(struct bt_info
));
180 addr
.off
= frame
->ip
;
181 frames
[frameno
].eip
= addr
.off
;
182 frames
[frameno
].ebp
= frame
->bp
;
183 DEBUG_FindNearestSymbol( &addr
, TRUE
,
184 &frames
[frameno
].frame
.sym
, frame
->bp
,
185 &frames
[frameno
].frame
.list
);
187 addr
.off
= frame
->bp
;
190 else /* 16-bit mode */
193 * Not implemented here. I am not entirely sure how best to handle
200 DEBUG_SetFrame(int newframe
)
204 curr_frame
= newframe
;
206 if( curr_frame
>= nframe
)
208 curr_frame
= nframe
- 1;
216 if( frames
[curr_frame
].frame
.list
.sourcefile
!= NULL
)
218 DEBUG_List(&frames
[curr_frame
].frame
.list
, NULL
, 0);
226 DEBUG_GetCurrentFrame(struct name_hash
** name
, unsigned int * eip
,
230 * If we don't have a valid backtrace, then just return.
238 * If we don't know what the current function is, then we also have
239 * nothing to report here.
241 if( frames
[curr_frame
].frame
.sym
== NULL
)
246 *name
= frames
[curr_frame
].frame
.sym
;
247 *eip
= frames
[curr_frame
].eip
;
248 *ebp
= frames
[curr_frame
].ebp
;