Debugger is now called by exception handling.
[wine] / debugger / info.c
1 /*
2  * Wine debugger utility routines
3  *
4  * Copyright 1993 Eric Youngdale
5  * Copyright 1995 Alexandre Julliard
6  */
7
8 #include "config.h"
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include "debugger.h"
12 #include "expr.h"
13
14 /***********************************************************************
15  *           DEBUG_PrintBasic
16  *
17  * Implementation of the 'print' command.
18  */
19 void DEBUG_PrintBasic( const DBG_ADDR *addr, int count, char format )
20 {
21   char        * default_format;
22   long long int value;
23
24   if( addr->type == NULL )
25     {
26       fprintf(stderr, "Unable to evaluate expression\n");
27       return;
28     }
29   
30   default_format = NULL;
31   value = DEBUG_GetExprValue((DBG_ADDR *) addr, &default_format);
32
33   switch(format)
34     {
35     case 'x':
36       if (addr->seg) 
37         {
38           DEBUG_nchar += fprintf( stderr, "0x%04lx", (long unsigned int) value );
39         }
40       else 
41         {
42           DEBUG_nchar += fprintf( stderr, "0x%08lx", (long unsigned int) value );
43         }
44       break;
45       
46     case 'd':
47       DEBUG_nchar += fprintf( stderr, "%ld\n", (long int) value );
48       break;
49       
50     case 'c':
51       DEBUG_nchar += fprintf( stderr, "%d = '%c'",
52                (char)(value & 0xff), (char)(value & 0xff) );
53       break;
54       
55     case 'i':
56     case 's':
57     case 'w':
58     case 'b':
59       fprintf( stderr, "Format specifier '%c' is meaningless in 'print' command\n", format );
60     case 0:
61       if( default_format != NULL )
62         {
63           DEBUG_nchar += fprintf( stderr, default_format, value );
64         }
65       break;
66     }
67 }
68
69
70 /***********************************************************************
71  *           DEBUG_PrintAddress
72  *
73  * Print an 16- or 32-bit address, with the nearest symbol if any.
74  */
75 struct symbol_info
76 DEBUG_PrintAddress( const DBG_ADDR *addr, int addrlen, int flag )
77 {
78     struct symbol_info rtn;
79
80     const char *name = DEBUG_FindNearestSymbol( addr, flag, &rtn.sym, 0, 
81                                                 &rtn.list );
82
83     if (addr->seg) fprintf( stderr, "0x%04lx:", addr->seg&0xFFFF );
84     if (addrlen == 16) fprintf( stderr, "0x%04lx", addr->off );
85     else fprintf( stderr, "0x%08lx", addr->off );
86     if (name) fprintf( stderr, " (%s)", name );
87     return rtn;
88 }
89 /***********************************************************************
90  *           DEBUG_PrintAddressAndArgs
91  *
92  * Print an 16- or 32-bit address, with the nearest symbol if any.
93  * Similar to DEBUG_PrintAddress, but we print the arguments to
94  * each function (if known).  This is useful in a backtrace.
95  */
96 struct symbol_info
97 DEBUG_PrintAddressAndArgs( const DBG_ADDR *addr, int addrlen, 
98                            unsigned int ebp, int flag )
99 {
100     struct symbol_info rtn;
101
102     const char *name = DEBUG_FindNearestSymbol( addr, flag, &rtn.sym, ebp, 
103                                                 &rtn.list );
104
105     if (addr->seg) fprintf( stderr, "0x%04lx:", addr->seg );
106     if (addrlen == 16) fprintf( stderr, "0x%04lx", addr->off );
107     else fprintf( stderr, "0x%08lx", addr->off );
108     if (name) fprintf( stderr, " (%s)", name );
109
110     return rtn;
111 }
112
113
114 /***********************************************************************
115  *           DEBUG_Help
116  *
117  * Implementation of the 'help' command.
118  */
119 void DEBUG_Help(void)
120 {
121     int i = 0;
122     static const char * const helptext[] =
123 {
124 "The commands accepted by the Wine debugger are a reasonable",
125 "subset of the commands that gdb accepts.",
126 "The commands currently are:",
127 "  help                                   quit",
128 "  break [*<addr>]                        delete break bpnum",
129 "  disable bpnum                          enable bpnum",
130 "  condition <bpnum> [<expr>]             pass",
131 "  bt                                     cont [N]",
132 "  step [N]                               next [N]",
133 "  stepi [N]                              nexti [N]",
134 "  x <addr>                               print <expr>",
135 "  set <reg> = <expr>                     set *<addr> = <expr>",
136 "  up                                     down",
137 "  list <lines>                           disassemble [<addr>][,<addr>]",
138 "  frame <n>                              finish",
139 "  show dir                               dir <path>",
140 "  display <expr>                         undisplay <disnum>",
141 "  delete display <disnum>                debugmsg <class>[-+]<type>\n",
142 "  mode [16,32]                           walk [wnd,class,queue,module,",
143 "                                               process,modref <pid>]",
144 "  info (see 'help info' for options)\n",
145
146 "The 'x' command accepts repeat counts and formats (including 'i') in the",
147 "same way that gdb does.\n",
148
149 " The following are examples of legal expressions:",
150 " $eax     $eax+0x3   0x1000   ($eip + 256)  *$eax   *($esp + 3)",
151 " Also, a nm format symbol table can be read from a file using the",
152 " symbolfile command.  Symbols can also be defined individually with",
153 " the define command.",
154 "",
155 NULL
156 };
157
158     while(helptext[i]) fprintf(stderr,"%s\n", helptext[i++]);
159 }
160
161
162 /***********************************************************************
163  *           DEBUG_HelpInfo
164  *
165  * Implementation of the 'help info' command.
166  */
167 void DEBUG_HelpInfo(void)
168 {
169     int i = 0;
170     static const char * const infotext[] =
171 {
172 "The info commands allow you to get assorted bits of interesting stuff",
173 "to be displayed.  The options are:",
174 "  info break           Dumps information about breakpoints",
175 "  info display         Shows auto-display expressions in use",
176 "  info locals          Displays values of all local vars for current frame",
177 "  info maps            Dumps all virtual memory mappings",
178 "  info module <handle> Displays internal module state",
179 "  info queue <handle>  Displays internal queue state",
180 "  info reg             Displays values in all registers at top of stack",
181 "  info segments        Dumps information about all known segments",
182 "  info share           Dumps information about shared libraries",
183 "  info stack           Dumps information about top of stack",
184 "  info wnd <handle>    Displays internal window state",
185 "",
186 NULL
187 };
188
189     while(infotext[i]) fprintf(stderr,"%s\n", infotext[i++]);
190 }