draft
[gdbmicli.git] / libmigdb / src / stack_man.c
1 /**[txh]********************************************************************
2
3   Copyright (c) 2004 by Salvador E. Tropea.
4   Covered by the GPL license.
5
6   Module: Stack manipulation.
7   Comments:
8   GDB/MI commands for the "Stack Manipulation" section.@p
9
10 @<pre>
11 gdb command:              Implemented?
12
13 -stack-info-frame         Yes, implemented as "frame"
14 -stack-info-depth         Yes
15 -stack-list-arguments     Yes
16 -stack-list-frames        Yes
17 -stack-list-locals        Yes
18 -stack-select-frame       Yes
19 @</pre>
20
21 ***************************************************************************/
22
23 #include "mi_gdb.h"
24
25 /* Low level versions. */
26
27 void mi_stack_list_frames(mi_h *h, int from, int to)
28 {
29  if (from<0)
30     mi_send(h,"-stack-list-frames\n");
31  else
32     mi_send(h,"-stack-list-frames %d %d\n",from,to);
33 }
34
35 void mi_stack_list_arguments(mi_h *h, int show, int from, int to)
36 {
37  if (from<0)
38     mi_send(h,"-stack-list-arguments %d\n",show);
39  else
40     mi_send(h,"-stack-list-arguments %d %d %d\n",show,from,to);
41 }
42
43 void mi_stack_info_frame(mi_h *h)
44 {
45  mi_send(h,"frame\n");
46 }
47
48 void mi_stack_info_depth(mi_h *h, int depth)
49 {
50  if (depth<0)
51     mi_send(h,"-stack-info-depth\n");
52  else
53     mi_send(h,"-stack-info-depth %d\n",depth);
54 }
55
56 void mi_stack_select_frame(mi_h *h, int framenum)
57 {
58  mi_send(h,"-stack-select-frame %d\n",framenum);
59 }
60
61 void mi_stack_list_locals(mi_h *h, int show)
62 {
63  mi_send(h,"-stack-list-locals %d\n",show);
64 }
65
66 /* High level versions. */
67
68 /**[txh]********************************************************************
69
70   Description:
71   List of frames. Arguments aren't filled.
72
73   Command: -stack-list-frames
74   Return:  A new list of mi_frames or NULL on error.
75   
76 ***************************************************************************/
77
78 mi_frames *gmi_stack_list_frames(mi_h *h)
79 {
80  mi_stack_list_frames(h,-1,-1);
81  return mi_res_frames_array(h,"stack");
82 }
83
84 /**[txh]********************************************************************
85
86   Description: 
87   List of frames. Arguments aren't filled. Only the frames in the @var{from}
88  - @var{to} range are returned.
89   
90   Command: -stack-list-frames
91   Return:  A new list of mi_frames or NULL on error.
92   
93 ***************************************************************************/
94
95 mi_frames *gmi_stack_list_frames_r(mi_h *h, int from, int to)
96 {
97  mi_stack_list_frames(h,from,to);
98  return mi_res_frames_array(h,"stack");
99 }
100
101 /**[txh]********************************************************************
102
103   Description:
104   List arguments. Only @var{level} and @var{args} filled.
105   
106   Command: -stack-list-arguments
107   Return:  A new list of mi_frames or NULL on error.
108   
109 ***************************************************************************/
110
111 mi_frames *gmi_stack_list_arguments(mi_h *h, int show)
112 {
113  mi_stack_list_arguments(h,show,-1,-1);
114  return mi_res_frames_array(h,"stack-args");
115 }
116
117 /**[txh]********************************************************************
118
119   Description:
120   List arguments. Only @var{level} and @var{args} filled. Only for the
121 frames in the @var{from} - @var{to} range.
122   
123   Command: -stack-list-arguments
124   Return:  A new list of mi_frames or NULL on error.
125   
126 ***************************************************************************/
127
128 mi_frames *gmi_stack_list_arguments_r(mi_h *h, int show, int from, int to)
129 {
130  mi_stack_list_arguments(h,show,from,to);
131  return mi_res_frames_array(h,"stack-args");
132 }
133
134 /**[txh]********************************************************************
135
136   Description:
137   Information about the current frame, including args.
138
139   Command: -stack-info-frame [using frame]
140   Return: A new mi_frames or NULL on error.
141   
142 ***************************************************************************/
143
144 mi_frames *gmi_stack_info_frame(mi_h *h)
145 {
146  mi_stack_info_frame(h);
147  return mi_res_frame(h);
148 }
149
150 /**[txh]********************************************************************
151
152   Description:
153   Stack info depth.
154
155   Command: -stack-info-depth
156   Return: The depth or -1 on error.
157   
158 ***************************************************************************/
159
160 int gmi_stack_info_depth(mi_h *h, int max_depth)
161 {
162  mi_results *r;
163  int ret=-1;
164
165  mi_stack_info_depth(h,max_depth);
166  r=mi_res_done_var(h,"depth");
167  if (r && r->type==t_const)
168    {
169     ret=atoi(r->v.cstr);
170     mi_free_results(r);
171    }
172  return ret;
173 }
174
175 /**[txh]********************************************************************
176
177   Description:
178   Set stack info depth.
179
180   Command: -stack-info-depth [no args]
181   Return: The depth or -1 on error.
182   Example: 
183   
184 ***************************************************************************/
185
186 int gmi_stack_info_depth_get(mi_h *h)
187 {
188  return gmi_stack_info_depth(h,-1);
189 }
190
191 /**[txh]********************************************************************
192
193   Description:
194   Change current frame.
195
196   Command: -stack-select-frame
197   Return: !=0 OK
198   
199 ***************************************************************************/
200
201 int gmi_stack_select_frame(mi_h *h, int framenum)
202 {
203  mi_stack_select_frame(h,framenum);
204  return mi_res_simple_done(h);
205 }
206
207 /**[txh]********************************************************************
208
209   Description:
210   List of local vars.
211
212   Command: -stack-list-locals
213   Return: A new mi_results tree containing the variables or NULL on error.
214   
215 ***************************************************************************/
216
217 mi_results *gmi_stack_list_locals(mi_h *h, int show)
218 {
219  mi_stack_list_locals(h,show);
220  return mi_res_done_var(h,"locals");
221 }
222