cvs -z3 -d:pserver:anonymous@libmigdb.cvs.sourceforge.net:/cvsroot/libmigdb co -P...
[gdbmicli.git] / src / data_man.c
1 /**[txh]********************************************************************
2
3   Copyright (c) 2004 by Salvador E. Tropea.
4   Covered by the GPL license.
5
6   Module: Data manipulation.
7   Comments:
8   GDB/MI commands for the "Data manipulation" section.@p
9
10 @<pre>
11 gdb command:                       Implemented?
12
13 -data-disassemble                  Yes
14 -data-evaluate-expression          Yes
15 -data-list-changed-registers       No
16 -data-list-register-names          Yes
17 -data-list-register-values         No
18 -data-read-memory                  No
19 -display-delete                    N.A. (delete display)
20 -display-disable                   N.A. (disable display)
21 -display-enable                    N.A. (enable display)
22 -display-insert                    N.A. (display)
23 -display-list                      N.A. (info display)
24 -environment-cd                    No
25 -environment-directory             Yes, MI v1 implementation
26 -environment-path                  No
27 @</pre>
28
29 Notes:@p
30
31 1) -display* aren't implemented. You can use CLI command display, but the
32 results are sent to the console. So it looks like the best is to manually
33 use -data-evaluate-expression to emulate it.@p
34
35 2) GDB bug mi/1770: Affects gdb<=6.2, when you ask for the names of the
36 registers you get it plus the name of the "pseudo-registers", but if you
37 try to get the value of a pseudo-register you get an error saying the
38 register number is invalid. I reported to gdb-patches@sources.redhat.com
39 on 2004/08/25 and as I didn't get any answer I filled a bug report on
40 2004/09/02. The patch to fix this annoying bug is:
41
42 Index: gdb/mi/mi-main.c
43 ===================================================================
44 RCS file: /cvs/src/src/gdb/mi/mi-main.c,v
45 retrieving revision 1.64
46 diff -u -r1.64 mi-main.c
47 --- gdb/mi/mi-main.c    3 Aug 2004 00:57:27 -0000       1.64
48 +++ gdb/mi/mi-main.c    25 Aug 2004 14:12:50 -0000
49 @@ -423,7 +423,7 @@
50       case, some entries of REGISTER_NAME will change depending upon
51       the particular processor being debugged.
52
53 -  numregs = NUM_REGS;
54 +  numregs = NUM_REGS + NUM_PSEUDO_REGS;
55
56    if (argc == 0)
57      {
58 ----
59
60 Note I had to remove an end of comment in the patch to include it here.
61 This bug forced me to create another set of functions. The only way is to
62 first get the values and then the names.
63 Fixed by Changelog entry:
64
65 2004-09-12  Salvador E. Tropea  <set@users.sf.net>
66             Andrew Cagney  <cagney@gnu.org>
67
68         * mi/mi-main.c (mi_cmd_data_list_changed_registers)
69         (mi_cmd_data_list_register_values)
70         (mi_cmd_data_write_register_values): Include the PSEUDO_REGS in
71         the register number computation.
72
73 ***************************************************************************/
74
75 #include "mi_gdb.h"
76
77 /* Low level versions. */
78
79 void mi_data_evaluate_expression(mi_h *h, const char *expression)
80 {
81  mi_send(h,"-data-evaluate-expression \"%s\"\n",expression);
82 }
83
84 void mi_dir(mi_h *h, const char *path)
85 {
86  if (h->version>=MI_VERSION2U(2,0,0))
87    {// MI v2
88     if (path)
89        mi_send(h,"-environment-directory \"%s\"\n",path);
90     else
91        mi_send(h,"-environment-directory -r\n");
92    }
93  else
94    {
95     mi_send(h,"-environment-directory %s\n",path ? path : "");
96    }
97 }
98
99 void mi_data_read_memory_hx(mi_h *h, const char *exp, unsigned ws,
100                             unsigned c, int convAddr)
101 {
102  if (convAddr)
103     mi_send(h,"-data-read-memory \"&%s\" x %d 1 %d\n",exp,ws,c);
104  else
105     mi_send(h,"-data-read-memory \"%s\" x %d 1 %d\n",exp,ws,c);
106 }
107
108 void mi_data_disassemble_se(mi_h *h, const char *start, const char *end,
109                             int mode)
110 {
111  mi_send(h,"-data-disassemble -s \"%s\" -e \"%s\" -- %d\n",start,end,mode);
112 }
113
114 void mi_data_disassemble_fl(mi_h *h, const char *file, int line, int lines,
115                             int mode)
116 {
117  mi_send(h,"-data-disassemble -f \"%s\" -l %d -n %d -- %d\n",file,line,lines,
118          mode);
119 }
120
121 void mi_data_list_register_names(mi_h *h)
122 {
123  mi_send(h,"-data-list-register-names\n");
124 }
125
126 void mi_data_list_register_names_l(mi_h *h, mi_chg_reg *l)
127 {
128  mi_send(h,"-data-list-register-names ");
129  while (l)
130    {
131     mi_send(h,"%d ",l->reg);
132     l=l->next;
133    }
134  mi_send(h,"\n");
135 }
136
137 void mi_data_list_changed_registers(mi_h *h)
138 {
139  mi_send(h,"-data-list-changed-registers\n");
140 }
141
142 void mi_data_list_register_values(mi_h *h, enum mi_gvar_fmt fmt, mi_chg_reg *l)
143 {
144  mi_send(h,"-data-list-register-values %c ",mi_format_enum_to_char(fmt));
145  while (l)
146    {
147     mi_send(h,"%d ",l->reg);
148     l=l->next;
149    }
150  mi_send(h,"\n");
151 }
152
153 /* High level versions. */
154
155 /**[txh]********************************************************************
156
157   Description:
158   Evaluate an expression. Returns a parsed tree.
159
160   Command: -data-evaluate-expression
161   Return: The resulting value (as plain text) or NULL on error.
162   
163 ***************************************************************************/
164
165 char *gmi_data_evaluate_expression(mi_h *h, const char *expression)
166 {
167  mi_data_evaluate_expression(h,expression);
168  return mi_res_value(h);
169 }
170
171 /**[txh]********************************************************************
172
173   Description:
174   Path for sources. You must use it to indicate where are the sources for
175 the program to debug. Only the MI v1 implementation is available.
176
177   Command: -environment-directory
178   Return: !=0 OK
179   
180 ***************************************************************************/
181
182 int gmi_dir(mi_h *h, const char *path)
183 {
184  mi_dir(h,path);
185  return mi_res_simple_done(h);
186 }
187
188 int gmi_read_memory(mi_h *h, const char *exp, unsigned size,
189                     unsigned char *dest, int *na, int convAddr,
190                     unsigned long *addr)
191 {
192  mi_data_read_memory_hx(h,exp,1,size,convAddr);
193  return mi_get_read_memory(h,dest,1,na,addr);
194 }
195
196 mi_asm_insns *gmi_data_disassemble_se(mi_h *h, const char *start,
197                                       const char *end, int mode)
198 {
199  mi_data_disassemble_se(h,start,end,mode);
200  return mi_get_asm_insns(h);
201 }
202
203 mi_asm_insns *gmi_data_disassemble_fl(mi_h *h, const char *file, int line,
204                                       int lines, int mode)
205 {
206  mi_data_disassemble_fl(h,file,line,lines,mode);
207  return mi_get_asm_insns(h);
208 }
209
210 // Affected by gdb bug mi/1770
211 mi_chg_reg *gmi_data_list_register_names(mi_h *h, int *how_many)
212 {
213  mi_data_list_register_names(h);
214  return mi_get_list_registers(h,how_many);
215 }
216
217 int gmi_data_list_register_names_l(mi_h *h, mi_chg_reg *l)
218 {
219  mi_data_list_register_names_l(h,l);
220  return mi_get_list_registers_l(h,l);
221 }
222
223 mi_chg_reg *gmi_data_list_changed_registers(mi_h *h)
224 {
225  mi_error=MI_OK;
226  mi_data_list_changed_registers(h);
227  return mi_get_list_changed_regs(h);
228 }
229
230 int gmi_data_list_register_values(mi_h *h, enum mi_gvar_fmt fmt, mi_chg_reg *l)
231 {
232  mi_data_list_register_values(h,fmt,l);
233  return mi_get_reg_values(h,l);
234 }
235
236 mi_chg_reg *gmi_data_list_all_register_values(mi_h *h, enum mi_gvar_fmt fmt, int *how_many)
237 {
238  mi_data_list_register_values(h,fmt,NULL);
239  return mi_get_reg_values_l(h,how_many);
240 }
241