Bug Summary

File:src/gnu/usr.bin/binutils/gdb/mi/mi-cmd-var.c
Warning:line 61, column 3
Value stored to 'old_cleanups' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name mi-cmd-var.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 1 -pic-is-pie -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-feature +retpoline-indirect-calls -target-feature +retpoline-indirect-branches -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/gnu/usr.bin/binutils/obj/gdb -resource-dir /usr/local/lib/clang/13.0.0 -D PIE_DEFAULT=1 -I . -I /usr/src/gnu/usr.bin/binutils/gdb -I /usr/src/gnu/usr.bin/binutils/gdb/config -D LOCALEDIR="/usr/share/locale" -D HAVE_CONFIG_H -I /usr/src/gnu/usr.bin/binutils/gdb/../include/opcode -I ../bfd -I /usr/src/gnu/usr.bin/binutils/gdb/../bfd -I /usr/src/gnu/usr.bin/binutils/gdb/../include -I ../intl -I /usr/src/gnu/usr.bin/binutils/gdb/../intl -D MI_OUT=1 -D TUI=1 -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/gnu/usr.bin/binutils/obj/gdb -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fgnuc-version=4.2.1 -fcommon -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c /usr/src/gnu/usr.bin/binutils/gdb/mi/mi-cmd-var.c
1/* MI Command Set - varobj commands.
2
3 Copyright 2000, 2002, 2004 Free Software Foundation, Inc.
4
5 Contributed by Cygnus Solutions (a Red Hat company).
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
23
24#include "defs.h"
25#include "mi-cmds.h"
26#include "ui-out.h"
27#include "mi-out.h"
28#include "varobj.h"
29#include "value.h"
30#include <ctype.h>
31#include "gdb_string.h"
32
33extern int varobjdebug; /* defined in varobj.c */
34
35static int varobj_update_one (struct varobj *var);
36
37/* VAROBJ operations */
38
39enum mi_cmd_result
40mi_cmd_var_create (char *command, char **argv, int argc)
41{
42 CORE_ADDR frameaddr = 0;
43 struct varobj *var;
44 char *name;
45 char *frame;
46 char *expr;
47 char *type;
48 struct cleanup *old_cleanups;
49 enum varobj_type var_type;
50
51 if (argc != 3)
52 {
53 /* mi_error_message = xstrprintf ("mi_cmd_var_create: Usage:
54 ...."); return MI_CMD_ERROR; */
55 error ("mi_cmd_var_create: Usage: NAME FRAME EXPRESSION.");
56 }
57
58 name = xstrdup (argv[0]);
59 /* Add cleanup for name. Must be free_current_contents as
60 name can be reallocated */
61 old_cleanups = make_cleanup (free_current_contents, &name);
Value stored to 'old_cleanups' is never read
62
63 frame = xstrdup (argv[1]);
64 old_cleanups = make_cleanup (xfree, frame);
65
66 expr = xstrdup (argv[2]);
67
68 if (strcmp (name, "-") == 0)
69 {
70 xfree (name);
71 name = varobj_gen_name ();
72 }
73 else if (!isalpha (*name))
74 error ("mi_cmd_var_create: name of object must begin with a letter");
75
76 if (strcmp (frame, "*") == 0)
77 var_type = USE_CURRENT_FRAME;
78 else if (strcmp (frame, "@") == 0)
79 var_type = USE_SELECTED_FRAME;
80 else
81 {
82 var_type = USE_SPECIFIED_FRAME;
83 frameaddr = string_to_core_addr (frame);
84 }
85
86 if (varobjdebug)
87 fprintf_unfiltered (gdb_stdlog,
88 "Name=\"%s\", Frame=\"%s\" (0x%s), Expression=\"%s\"\n",
89 name, frame, paddr (frameaddr), expr);
90
91 var = varobj_create (name, expr, frameaddr, var_type);
92
93 if (var == NULL((void*)0))
94 error ("mi_cmd_var_create: unable to create variable object");
95
96 ui_out_field_string (uiout, "name", name);
97 ui_out_field_int (uiout, "numchild", varobj_get_num_children (var));
98 type = varobj_get_type (var);
99 if (type == NULL((void*)0))
100 ui_out_field_string (uiout, "type", "");
101 else
102 {
103 ui_out_field_string (uiout, "type", type);
104 xfree (type);
105 }
106
107 do_cleanups (old_cleanups);
108 return MI_CMD_DONE;
109}
110
111enum mi_cmd_result
112mi_cmd_var_delete (char *command, char **argv, int argc)
113{
114 char *name;
115 char *expr;
116 struct varobj *var;
117 int numdel;
118 int children_only_p = 0;
119 struct cleanup *old_cleanups;
120
121 if (argc < 1 || argc > 2)
122 error ("mi_cmd_var_delete: Usage: [-c] EXPRESSION.");
123
124 name = xstrdup (argv[0]);
125 /* Add cleanup for name. Must be free_current_contents as
126 name can be reallocated */
127 old_cleanups = make_cleanup (free_current_contents, &name);
128
129 /* If we have one single argument it cannot be '-c' or any string
130 starting with '-'. */
131 if (argc == 1)
132 {
133 if (strcmp (name, "-c") == 0)
134 error ("mi_cmd_var_delete: Missing required argument after '-c': variable object name");
135 if (*name == '-')
136 error ("mi_cmd_var_delete: Illegal variable object name");
137 }
138
139 /* If we have 2 arguments they must be '-c' followed by a string
140 which would be the variable name. */
141 if (argc == 2)
142 {
143 expr = xstrdup (argv[1]);
144 if (strcmp (name, "-c") != 0)
145 error ("mi_cmd_var_delete: Invalid option.");
146 children_only_p = 1;
147 xfree (name);
148 name = xstrdup (expr);
149 xfree (expr);
150 }
151
152 /* If we didn't error out, now NAME contains the name of the
153 variable. */
154
155 var = varobj_get_handle (name);
156
157 if (var == NULL((void*)0))
158 error ("mi_cmd_var_delete: Variable object not found.");
159
160 numdel = varobj_delete (var, NULL((void*)0), children_only_p);
161
162 ui_out_field_int (uiout, "ndeleted", numdel);
163
164 do_cleanups (old_cleanups);
165 return MI_CMD_DONE;
166}
167
168enum mi_cmd_result
169mi_cmd_var_set_format (char *command, char **argv, int argc)
170{
171 enum varobj_display_formats format;
172 int len;
173 struct varobj *var;
174 char *formspec;
175
176 if (argc != 2)
177 error ("mi_cmd_var_set_format: Usage: NAME FORMAT.");
178
179 /* Get varobj handle, if a valid var obj name was specified */
180 var = varobj_get_handle (argv[0]);
181
182 if (var == NULL((void*)0))
183 error ("mi_cmd_var_set_format: Variable object not found");
184
185 formspec = xstrdup (argv[1]);
186 if (formspec == NULL((void*)0))
187 error ("mi_cmd_var_set_format: Must specify the format as: \"natural\", \"binary\", \"decimal\", \"hexadecimal\", or \"octal\"");
188
189 len = strlen (formspec);
190
191 if (strncmp (formspec, "natural", len) == 0)
192 format = FORMAT_NATURAL;
193 else if (strncmp (formspec, "binary", len) == 0)
194 format = FORMAT_BINARY;
195 else if (strncmp (formspec, "decimal", len) == 0)
196 format = FORMAT_DECIMAL;
197 else if (strncmp (formspec, "hexadecimal", len) == 0)
198 format = FORMAT_HEXADECIMAL;
199 else if (strncmp (formspec, "octal", len) == 0)
200 format = FORMAT_OCTAL;
201 else
202 error ("mi_cmd_var_set_format: Unknown display format: must be: \"natural\", \"binary\", \"decimal\", \"hexadecimal\", or \"octal\"");
203
204 /* Set the format of VAR to given format */
205 varobj_set_display_format (var, format);
206
207 /* Report the new current format */
208 ui_out_field_string (uiout, "format", varobj_format_string[(int) format]);
209 return MI_CMD_DONE;
210}
211
212enum mi_cmd_result
213mi_cmd_var_show_format (char *command, char **argv, int argc)
214{
215 enum varobj_display_formats format;
216 struct varobj *var;
217
218 if (argc != 1)
219 error ("mi_cmd_var_show_format: Usage: NAME.");
220
221 /* Get varobj handle, if a valid var obj name was specified */
222 var = varobj_get_handle (argv[0]);
223 if (var == NULL((void*)0))
224 error ("mi_cmd_var_show_format: Variable object not found");
225
226 format = varobj_get_display_format (var);
227
228 /* Report the current format */
229 ui_out_field_string (uiout, "format", varobj_format_string[(int) format]);
230 return MI_CMD_DONE;
231}
232
233enum mi_cmd_result
234mi_cmd_var_info_num_children (char *command, char **argv, int argc)
235{
236 struct varobj *var;
237
238 if (argc != 1)
239 error ("mi_cmd_var_info_num_children: Usage: NAME.");
240
241 /* Get varobj handle, if a valid var obj name was specified */
242 var = varobj_get_handle (argv[0]);
243 if (var == NULL((void*)0))
244 error ("mi_cmd_var_info_num_children: Variable object not found");
245
246 ui_out_field_int (uiout, "numchild", varobj_get_num_children (var));
247 return MI_CMD_DONE;
248}
249
250enum mi_cmd_result
251mi_cmd_var_list_children (char *command, char **argv, int argc)
252{
253 struct varobj *var;
254 struct varobj **childlist;
255 struct varobj **cc;
256 struct cleanup *cleanup_children;
257 int numchild;
258 char *type;
259 enum print_values print_values;
260
261 if (argc != 1 && argc != 2)
262 error ("mi_cmd_var_list_children: Usage: [PRINT_VALUES] NAME");
263
264 /* Get varobj handle, if a valid var obj name was specified */
265 if (argc == 1) var = varobj_get_handle (argv[0]);
266 else var = varobj_get_handle (argv[1]);
267 if (var == NULL((void*)0))
268 error ("Variable object not found");
269
270 numchild = varobj_list_children (var, &childlist);
271 ui_out_field_int (uiout, "numchild", numchild);
272 if (argc == 2)
273 if (strcmp (argv[0], "0") == 0
274 || strcmp (argv[0], "--no-values") == 0)
275 print_values = PRINT_NO_VALUES;
276 else if (strcmp (argv[0], "1") == 0
277 || strcmp (argv[0], "--all-values") == 0)
278 print_values = PRINT_ALL_VALUES;
279 else
280 error ("Unknown value for PRINT_VALUES: must be: 0 or \"--no-values\", 1 or \"--all-values\"");
281 else print_values = PRINT_NO_VALUES;
282
283 if (numchild <= 0)
284 return MI_CMD_DONE;
285
286 if (mi_version (uiout) == 1)
287 cleanup_children = make_cleanup_ui_out_tuple_begin_end (uiout, "children");
288 else
289 cleanup_children = make_cleanup_ui_out_list_begin_end (uiout, "children");
290 cc = childlist;
291 while (*cc != NULL((void*)0))
292 {
293 struct cleanup *cleanup_child;
294 cleanup_child = make_cleanup_ui_out_tuple_begin_end (uiout, "child");
295 ui_out_field_string (uiout, "name", varobj_get_objname (*cc));
296 ui_out_field_string (uiout, "exp", varobj_get_expression (*cc));
297 ui_out_field_int (uiout, "numchild", varobj_get_num_children (*cc));
298 if (print_values)
299 ui_out_field_string (uiout, "value", varobj_get_value (*cc));
300 type = varobj_get_type (*cc);
301 /* C++ pseudo-variables (public, private, protected) do not have a type */
302 if (type)
303 ui_out_field_string (uiout, "type", varobj_get_type (*cc));
304 do_cleanups (cleanup_child);
305 cc++;
306 }
307 do_cleanups (cleanup_children);
308 xfree (childlist);
309 return MI_CMD_DONE;
310}
311
312enum mi_cmd_result
313mi_cmd_var_info_type (char *command, char **argv, int argc)
314{
315 struct varobj *var;
316
317 if (argc != 1)
318 error ("mi_cmd_var_info_type: Usage: NAME.");
319
320 /* Get varobj handle, if a valid var obj name was specified */
321 var = varobj_get_handle (argv[0]);
322 if (var == NULL((void*)0))
323 error ("mi_cmd_var_info_type: Variable object not found");
324
325 ui_out_field_string (uiout, "type", varobj_get_type (var));
326 return MI_CMD_DONE;
327}
328
329enum mi_cmd_result
330mi_cmd_var_info_expression (char *command, char **argv, int argc)
331{
332 enum varobj_languages lang;
333 struct varobj *var;
334
335 if (argc != 1)
336 error ("mi_cmd_var_info_expression: Usage: NAME.");
337
338 /* Get varobj handle, if a valid var obj name was specified */
339 var = varobj_get_handle (argv[0]);
340 if (var == NULL((void*)0))
341 error ("mi_cmd_var_info_expression: Variable object not found");
342
343 lang = varobj_get_language (var);
344
345 ui_out_field_string (uiout, "lang", varobj_language_string[(int) lang]);
346 ui_out_field_string (uiout, "exp", varobj_get_expression (var));
347 return MI_CMD_DONE;
348}
349
350enum mi_cmd_result
351mi_cmd_var_show_attributes (char *command, char **argv, int argc)
352{
353 int attr;
354 char *attstr;
355 struct varobj *var;
356
357 if (argc != 1)
358 error ("mi_cmd_var_show_attributes: Usage: NAME.");
359
360 /* Get varobj handle, if a valid var obj name was specified */
361 var = varobj_get_handle (argv[0]);
362 if (var == NULL((void*)0))
363 error ("mi_cmd_var_show_attributes: Variable object not found");
364
365 attr = varobj_get_attributes (var);
366 /* FIXME: define masks for attributes */
367 if (attr & 0x00000001)
368 attstr = "editable";
369 else
370 attstr = "noneditable";
371
372 ui_out_field_string (uiout, "attr", attstr);
373 return MI_CMD_DONE;
374}
375
376enum mi_cmd_result
377mi_cmd_var_evaluate_expression (char *command, char **argv, int argc)
378{
379 struct varobj *var;
380
381 if (argc != 1)
382 error ("mi_cmd_var_evaluate_expression: Usage: NAME.");
383
384 /* Get varobj handle, if a valid var obj name was specified */
385 var = varobj_get_handle (argv[0]);
386 if (var == NULL((void*)0))
387 error ("mi_cmd_var_evaluate_expression: Variable object not found");
388
389 ui_out_field_string (uiout, "value", varobj_get_value (var));
390 return MI_CMD_DONE;
391}
392
393enum mi_cmd_result
394mi_cmd_var_assign (char *command, char **argv, int argc)
395{
396 struct varobj *var;
397 char *expression;
398
399 if (argc != 2)
400 error ("mi_cmd_var_assign: Usage: NAME EXPRESSION.");
401
402 /* Get varobj handle, if a valid var obj name was specified */
403 var = varobj_get_handle (argv[0]);
404 if (var == NULL((void*)0))
405 error ("mi_cmd_var_assign: Variable object not found");
406
407 /* FIXME: define masks for attributes */
408 if (!(varobj_get_attributes (var) & 0x00000001))
409 error ("mi_cmd_var_assign: Variable object is not editable");
410
411 expression = xstrdup (argv[1]);
412
413 if (!varobj_set_value (var, expression))
414 error ("mi_cmd_var_assign: Could not assign expression to varible object");
415
416 ui_out_field_string (uiout, "value", varobj_get_value (var));
417 return MI_CMD_DONE;
418}
419
420enum mi_cmd_result
421mi_cmd_var_update (char *command, char **argv, int argc)
422{
423 struct varobj *var;
424 struct varobj **rootlist;
425 struct varobj **cr;
426 struct cleanup *cleanup;
427 char *name;
428 int nv;
429
430 if (argc != 1)
431 error ("mi_cmd_var_update: Usage: NAME.");
432
433 name = argv[0];
434
435 /* Check if the parameter is a "*" which means that we want
436 to update all variables */
437
438 if ((*name == '*') && (*(name + 1) == '\0'))
439 {
440 nv = varobj_list (&rootlist);
441 if (mi_version (uiout) <= 1)
442 cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, "changelist");
443 else
444 cleanup = make_cleanup_ui_out_list_begin_end (uiout, "changelist");
445 if (nv <= 0)
446 {
447 do_cleanups (cleanup);
448 return MI_CMD_DONE;
449 }
450 cr = rootlist;
451 while (*cr != NULL((void*)0))
452 {
453 varobj_update_one (*cr);
454 cr++;
455 }
456 xfree (rootlist);
457 do_cleanups (cleanup);
458 }
459 else
460 {
461 /* Get varobj handle, if a valid var obj name was specified */
462 var = varobj_get_handle (name);
463 if (var == NULL((void*)0))
464 error ("mi_cmd_var_update: Variable object not found");
465
466 if (mi_version (uiout) <= 1)
467 cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, "changelist");
468 else
469 cleanup = make_cleanup_ui_out_list_begin_end (uiout, "changelist");
470 varobj_update_one (var);
471 do_cleanups (cleanup);
472 }
473 return MI_CMD_DONE;
474}
475
476/* Helper for mi_cmd_var_update() Returns 0 if the update for
477 the variable fails (usually because the variable is out of
478 scope), and 1 if it succeeds. */
479
480static int
481varobj_update_one (struct varobj *var)
482{
483 struct varobj **changelist;
484 struct varobj **cc;
485 struct cleanup *cleanup = NULL((void*)0);
486 int nc;
487
488 nc = varobj_update (&var, &changelist);
489
490 /* nc == 0 means that nothing has changed.
491 nc == -1 means that an error occured in updating the variable.
492 nc == -2 means the variable has changed type. */
493
494 if (nc == 0)
495 return 1;
496 else if (nc == -1)
497 {
498 if (mi_version (uiout) > 1)
499 cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, NULL((void*)0));
500 ui_out_field_string (uiout, "name", varobj_get_objname(var));
501 ui_out_field_string (uiout, "in_scope", "false");
502 if (mi_version (uiout) > 1)
503 do_cleanups (cleanup);
504 return -1;
505 }
506 else if (nc == -2)
507 {
508 if (mi_version (uiout) > 1)
509 cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, NULL((void*)0));
510 ui_out_field_string (uiout, "name", varobj_get_objname (var));
511 ui_out_field_string (uiout, "in_scope", "true");
512 ui_out_field_string (uiout, "new_type", varobj_get_type(var));
513 ui_out_field_int (uiout, "new_num_children",
514 varobj_get_num_children(var));
515 if (mi_version (uiout) > 1)
516 do_cleanups (cleanup);
517 }
518 else
519 {
520
521 cc = changelist;
522 while (*cc != NULL((void*)0))
523 {
524 if (mi_version (uiout) > 1)
525 cleanup = make_cleanup_ui_out_tuple_begin_end (uiout, NULL((void*)0));
526 ui_out_field_string (uiout, "name", varobj_get_objname (*cc));
527 ui_out_field_string (uiout, "in_scope", "true");
528 ui_out_field_string (uiout, "type_changed", "false");
529 if (mi_version (uiout) > 1)
530 do_cleanups (cleanup);
531 cc++;
532 }
533 xfree (changelist);
534 return 1;
535 }
536 return 1;
537}