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