Release 950918
[wine] / debugger / stack.c
1 /*
2  * Debugger stack handling
3  *
4  * Copyright 1995 Alexandre Julliard
5  */
6
7 #include <stdio.h>
8 #include "windows.h"
9 #include "debugger.h"
10
11
12 typedef struct
13 {
14     WORD bp;
15     WORD ip;
16     WORD cs;
17 } FRAME16;
18
19 typedef struct
20 {
21     DWORD bp;
22     DWORD ip;
23     WORD cs;
24 } FRAME32;
25
26
27
28 /***********************************************************************
29  *           DEBUG_InfoStack
30  *
31  * Dump the top of the stack
32  */
33 void DEBUG_InfoStack(void)
34 {
35     DBG_ADDR addr;
36
37     fprintf(stderr,"Stack dump:\n");
38     if ((SS_reg(DEBUG_context) == WINE_DATA_SELECTOR) ||
39         (GET_SEL_FLAGS(SS_reg(DEBUG_context)) & LDT_FLAGS_32BIT))
40     {  /* 32-bit mode */
41         addr.seg = 0;
42         addr.off = ESP_reg(DEBUG_context);
43         DEBUG_ExamineMemory( &addr, 10, 'x' );
44     }
45     else  /* 16-bit mode */
46     {
47         addr.seg = SS_reg(DEBUG_context);
48         addr.off = SP_reg(DEBUG_context);
49         DEBUG_ExamineMemory( &addr, 10, 'w' );
50     }
51     fprintf(stderr,"\n");
52 }
53
54
55 /***********************************************************************
56  *           DEBUG_BackTrace
57  *
58  * Display a stack back-trace.
59  */
60 void DEBUG_BackTrace(void)
61 {
62     DBG_ADDR addr;
63     int frameno = 0;
64
65   fprintf(stderr,"Backtrace:\n");
66   if (SS_reg(DEBUG_context) == WINE_DATA_SELECTOR)  /* 32-bit mode */
67   {
68       FRAME32 *frame = (FRAME32 *)EBP_reg(DEBUG_context);
69       addr.seg = 0;
70       while (frame->ip)
71       {
72           fprintf(stderr,"%d ",frameno++);
73           addr.off = frame->ip;
74           DEBUG_PrintAddress( &addr, 32 );
75           fprintf( stderr, "\n" );
76           frame = (FRAME32 *)frame->bp;
77       }
78   }
79   else  /* 16-bit mode */
80   {
81       FRAME16 *frame = (FRAME16 *)PTR_SEG_OFF_TO_LIN( SS_reg(DEBUG_context),
82                                                   BP_reg(DEBUG_context) & ~1 );
83       WORD cs = CS_reg(DEBUG_context);
84       if (GET_SEL_FLAGS(SS_reg(DEBUG_context)) & LDT_FLAGS_32BIT)
85       {
86           fprintf( stderr, "Not implemented: 32-bit backtrace on a different stack segment.\n" );
87           return;
88       }
89       while (frame->bp)
90       {
91           if (frame->bp & 1) cs = frame->cs;
92           fprintf( stderr,"%d ", frameno++ );
93           addr.seg = cs;
94           addr.off = frame->ip;
95           DEBUG_PrintAddress( &addr, 16 );
96           fprintf( stderr, "\n" );
97           frame = (FRAME16 *)PTR_SEG_OFF_TO_LIN( SS_reg(DEBUG_context),
98                                                  frame->bp & ~1 );
99       }
100   }
101   fprintf( stderr, "\n" );
102 }