Eliminate make_cleanup_ui_file_delete / make ui_file a class hierarchy
[deliverable/binutils-gdb.git] / gdb / python / py-framefilter.c
1 /* Python frame filters
2
3 Copyright (C) 2013-2017 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include "defs.h"
21 #include "objfiles.h"
22 #include "symtab.h"
23 #include "language.h"
24 #include "arch-utils.h"
25 #include "python.h"
26 #include "ui-out.h"
27 #include "valprint.h"
28 #include "annotate.h"
29 #include "hashtab.h"
30 #include "demangle.h"
31 #include "mi/mi-cmds.h"
32 #include "python-internal.h"
33 #include "py-ref.h"
34
35 enum mi_print_types
36 {
37 MI_PRINT_ARGS,
38 MI_PRINT_LOCALS
39 };
40
41 /* Helper function to extract a symbol, a name and a language
42 definition from a Python object that conforms to the "Symbol Value"
43 interface. OBJ is the Python object to extract the values from.
44 NAME is a pass-through argument where the name of the symbol will
45 be written. NAME is allocated in this function, but the caller is
46 responsible for clean up. SYM is a pass-through argument where the
47 symbol will be written and SYM_BLOCK is a pass-through argument to
48 write the block where the symbol lies in. In the case of the API
49 returning a string, this will be set to NULL. LANGUAGE is also a
50 pass-through argument denoting the language attributed to the
51 Symbol. In the case of SYM being NULL, this will be set to the
52 current language. Returns EXT_LANG_BT_ERROR on error with the
53 appropriate Python exception set, and EXT_LANG_BT_OK on success. */
54
55 static enum ext_lang_bt_status
56 extract_sym (PyObject *obj, gdb::unique_xmalloc_ptr<char> *name,
57 struct symbol **sym, struct block **sym_block,
58 const struct language_defn **language)
59 {
60 gdbpy_ref result (PyObject_CallMethod (obj, "symbol", NULL));
61
62 if (result == NULL)
63 return EXT_LANG_BT_ERROR;
64
65 /* For 'symbol' callback, the function can return a symbol or a
66 string. */
67 if (gdbpy_is_string (result.get ()))
68 {
69 *name = python_string_to_host_string (result.get ());
70
71 if (*name == NULL)
72 return EXT_LANG_BT_ERROR;
73 /* If the API returns a string (and not a symbol), then there is
74 no symbol derived language available and the frame filter has
75 either overridden the symbol with a string, or supplied a
76 entirely synthetic symbol/value pairing. In that case, use
77 python_language. */
78 *language = python_language;
79 *sym = NULL;
80 *sym_block = NULL;
81 }
82 else
83 {
84 /* This type checks 'result' during the conversion so we
85 just call it unconditionally and check the return. */
86 *sym = symbol_object_to_symbol (result.get ());
87 /* TODO: currently, we have no way to recover the block in which SYMBOL
88 was found, so we have no block to return. Trying to evaluate SYMBOL
89 will yield an incorrect value when it's located in a FRAME and
90 evaluated from another frame (as permitted in nested functions). */
91 *sym_block = NULL;
92
93 if (*sym == NULL)
94 {
95 PyErr_SetString (PyExc_RuntimeError,
96 _("Unexpected value. Expecting a "
97 "gdb.Symbol or a Python string."));
98 return EXT_LANG_BT_ERROR;
99 }
100
101 /* Duplicate the symbol name, so the caller has consistency
102 in garbage collection. */
103 name->reset (xstrdup (SYMBOL_PRINT_NAME (*sym)));
104
105 /* If a symbol is specified attempt to determine the language
106 from the symbol. If mode is not "auto", then the language
107 has been explicitly set, use that. */
108 if (language_mode == language_mode_auto)
109 *language = language_def (SYMBOL_LANGUAGE (*sym));
110 else
111 *language = current_language;
112 }
113
114 return EXT_LANG_BT_OK;
115 }
116
117 /* Helper function to extract a value from an object that conforms to
118 the "Symbol Value" interface. OBJ is the Python object to extract
119 the value from. VALUE is a pass-through argument where the value
120 will be written. If the object does not have the value attribute,
121 or provides the Python None for a value, VALUE will be set to NULL
122 and this function will return as successful. Returns EXT_LANG_BT_ERROR
123 on error with the appropriate Python exception set, and EXT_LANG_BT_OK on
124 success. */
125
126 static enum ext_lang_bt_status
127 extract_value (PyObject *obj, struct value **value)
128 {
129 if (PyObject_HasAttrString (obj, "value"))
130 {
131 gdbpy_ref vresult (PyObject_CallMethod (obj, "value", NULL));
132
133 if (vresult == NULL)
134 return EXT_LANG_BT_ERROR;
135
136 /* The Python code has returned 'None' for a value, so we set
137 value to NULL. This flags that GDB should read the
138 value. */
139 if (vresult == Py_None)
140 {
141 *value = NULL;
142 return EXT_LANG_BT_OK;
143 }
144 else
145 {
146 *value = convert_value_from_python (vresult.get ());
147
148 if (*value == NULL)
149 return EXT_LANG_BT_ERROR;
150
151 return EXT_LANG_BT_OK;
152 }
153 }
154 else
155 *value = NULL;
156
157 return EXT_LANG_BT_OK;
158 }
159
160 /* MI prints only certain values according to the type of symbol and
161 also what the user has specified. SYM is the symbol to check, and
162 MI_PRINT_TYPES is an enum specifying what the user wants emitted
163 for the MI command in question. */
164 static int
165 mi_should_print (struct symbol *sym, enum mi_print_types type)
166 {
167 int print_me = 0;
168
169 switch (SYMBOL_CLASS (sym))
170 {
171 default:
172 case LOC_UNDEF: /* catches errors */
173 case LOC_CONST: /* constant */
174 case LOC_TYPEDEF: /* local typedef */
175 case LOC_LABEL: /* local label */
176 case LOC_BLOCK: /* local function */
177 case LOC_CONST_BYTES: /* loc. byte seq. */
178 case LOC_UNRESOLVED: /* unresolved static */
179 case LOC_OPTIMIZED_OUT: /* optimized out */
180 print_me = 0;
181 break;
182
183 case LOC_ARG: /* argument */
184 case LOC_REF_ARG: /* reference arg */
185 case LOC_REGPARM_ADDR: /* indirect register arg */
186 case LOC_LOCAL: /* stack local */
187 case LOC_STATIC: /* static */
188 case LOC_REGISTER: /* register */
189 case LOC_COMPUTED: /* computed location */
190 if (type == MI_PRINT_LOCALS)
191 print_me = ! SYMBOL_IS_ARGUMENT (sym);
192 else
193 print_me = SYMBOL_IS_ARGUMENT (sym);
194 }
195 return print_me;
196 }
197
198 /* Helper function which outputs a type name extracted from VAL to a
199 "type" field in the output stream OUT. OUT is the ui-out structure
200 the type name will be output too, and VAL is the value that the
201 type will be extracted from. Returns EXT_LANG_BT_ERROR on error, with
202 any GDB exceptions converted to a Python exception, or EXT_LANG_BT_OK on
203 success. */
204
205 static enum ext_lang_bt_status
206 py_print_type (struct ui_out *out, struct value *val)
207 {
208
209 TRY
210 {
211 check_typedef (value_type (val));
212
213 string_file stb;
214 type_print (value_type (val), "", &stb, -1);
215 out->field_stream ("type", stb);
216 }
217 CATCH (except, RETURN_MASK_ALL)
218 {
219 gdbpy_convert_exception (except);
220 return EXT_LANG_BT_ERROR;
221 }
222 END_CATCH
223
224 return EXT_LANG_BT_OK;
225 }
226
227 /* Helper function which outputs a value to an output field in a
228 stream. OUT is the ui-out structure the value will be output to,
229 VAL is the value that will be printed, OPTS contains the value
230 printing options, ARGS_TYPE is an enumerator describing the
231 argument format, and LANGUAGE is the language_defn that the value
232 will be printed with. Returns EXT_LANG_BT_ERROR on error, with any GDB
233 exceptions converted to a Python exception, or EXT_LANG_BT_OK on
234 success. */
235
236 static enum ext_lang_bt_status
237 py_print_value (struct ui_out *out, struct value *val,
238 const struct value_print_options *opts,
239 int indent,
240 enum ext_lang_frame_args args_type,
241 const struct language_defn *language)
242 {
243 int should_print = 0;
244
245 /* MI does not print certain values, differentiated by type,
246 depending on what ARGS_TYPE indicates. Test type against option.
247 For CLI print all values. */
248 if (args_type == MI_PRINT_SIMPLE_VALUES
249 || args_type == MI_PRINT_ALL_VALUES)
250 {
251 struct type *type = NULL;
252
253 TRY
254 {
255 type = check_typedef (value_type (val));
256 }
257 CATCH (except, RETURN_MASK_ALL)
258 {
259 gdbpy_convert_exception (except);
260 return EXT_LANG_BT_ERROR;
261 }
262 END_CATCH
263
264 if (args_type == MI_PRINT_ALL_VALUES)
265 should_print = 1;
266 else if (args_type == MI_PRINT_SIMPLE_VALUES
267 && TYPE_CODE (type) != TYPE_CODE_ARRAY
268 && TYPE_CODE (type) != TYPE_CODE_STRUCT
269 && TYPE_CODE (type) != TYPE_CODE_UNION)
270 should_print = 1;
271 }
272 else if (args_type != NO_VALUES)
273 should_print = 1;
274
275 if (should_print)
276 {
277 TRY
278 {
279 string_file stb;
280
281 common_val_print (val, &stb, indent, opts, language);
282 out->field_stream ("value", stb);
283 }
284 CATCH (except, RETURN_MASK_ALL)
285 {
286 gdbpy_convert_exception (except);
287 return EXT_LANG_BT_ERROR;
288 }
289 END_CATCH
290 }
291
292 return EXT_LANG_BT_OK;
293 }
294
295 /* Helper function to call a Python method and extract an iterator
296 from the result. If the function returns anything but an iterator
297 the exception is preserved and NULL is returned. FILTER is the
298 Python object to call, and FUNC is the name of the method. Returns
299 a PyObject, or NULL on error with the appropriate exception set.
300 This function can return an iterator, or NULL. */
301
302 static PyObject *
303 get_py_iter_from_func (PyObject *filter, char *func)
304 {
305 if (PyObject_HasAttrString (filter, func))
306 {
307 gdbpy_ref result (PyObject_CallMethod (filter, func, NULL));
308
309 if (result != NULL)
310 {
311 if (result == Py_None)
312 {
313 return result.release ();
314 }
315 else
316 {
317 return PyObject_GetIter (result.get ());
318 }
319 }
320 }
321 else
322 Py_RETURN_NONE;
323
324 return NULL;
325 }
326
327 /* Helper function to output a single frame argument and value to an
328 output stream. This function will account for entry values if the
329 FV parameter is populated, the frame argument has entry values
330 associated with them, and the appropriate "set entry-value"
331 options are set. Will output in CLI or MI like format depending
332 on the type of output stream detected. OUT is the output stream,
333 SYM_NAME is the name of the symbol. If SYM_NAME is populated then
334 it must have an accompanying value in the parameter FV. FA is a
335 frame argument structure. If FA is populated, both SYM_NAME and
336 FV are ignored. OPTS contains the value printing options,
337 ARGS_TYPE is an enumerator describing the argument format,
338 PRINT_ARGS_FIELD is a flag which indicates if we output "ARGS=1"
339 in MI output in commands where both arguments and locals are
340 printed. Returns EXT_LANG_BT_ERROR on error, with any GDB exceptions
341 converted to a Python exception, or EXT_LANG_BT_OK on success. */
342
343 static enum ext_lang_bt_status
344 py_print_single_arg (struct ui_out *out,
345 const char *sym_name,
346 struct frame_arg *fa,
347 struct value *fv,
348 const struct value_print_options *opts,
349 enum ext_lang_frame_args args_type,
350 int print_args_field,
351 const struct language_defn *language)
352 {
353 struct value *val;
354 enum ext_lang_bt_status retval = EXT_LANG_BT_OK;
355
356 if (fa != NULL)
357 {
358 if (fa->val == NULL && fa->error == NULL)
359 return EXT_LANG_BT_OK;
360 language = language_def (SYMBOL_LANGUAGE (fa->sym));
361 val = fa->val;
362 }
363 else
364 val = fv;
365
366 TRY
367 {
368 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
369
370 /* MI has varying rules for tuples, but generally if there is only
371 one element in each item in the list, do not start a tuple. The
372 exception is -stack-list-variables which emits an ARGS="1" field
373 if the value is a frame argument. This is denoted in this
374 function with PRINT_ARGS_FIELD which is flag from the caller to
375 emit the ARGS field. */
376 if (out->is_mi_like_p ())
377 {
378 if (print_args_field || args_type != NO_VALUES)
379 make_cleanup_ui_out_tuple_begin_end (out, NULL);
380 }
381
382 annotate_arg_begin ();
383
384 /* If frame argument is populated, check for entry-values and the
385 entry value options. */
386 if (fa != NULL)
387 {
388 string_file stb;
389
390 fprintf_symbol_filtered (&stb, SYMBOL_PRINT_NAME (fa->sym),
391 SYMBOL_LANGUAGE (fa->sym),
392 DMGL_PARAMS | DMGL_ANSI);
393 if (fa->entry_kind == print_entry_values_compact)
394 {
395 stb.puts ("=");
396
397 fprintf_symbol_filtered (&stb, SYMBOL_PRINT_NAME (fa->sym),
398 SYMBOL_LANGUAGE (fa->sym),
399 DMGL_PARAMS | DMGL_ANSI);
400 }
401 if (fa->entry_kind == print_entry_values_only
402 || fa->entry_kind == print_entry_values_compact)
403 stb.puts ("@entry");
404 out->field_stream ("name", stb);
405 }
406 else
407 /* Otherwise, just output the name. */
408 out->field_string ("name", sym_name);
409
410 annotate_arg_name_end ();
411
412 if (! out->is_mi_like_p ())
413 out->text ("=");
414
415 if (print_args_field)
416 out->field_int ("arg", 1);
417
418 /* For MI print the type, but only for simple values. This seems
419 weird, but this is how MI choose to format the various output
420 types. */
421 if (args_type == MI_PRINT_SIMPLE_VALUES && val != NULL)
422 {
423 if (py_print_type (out, val) == EXT_LANG_BT_ERROR)
424 {
425 retval = EXT_LANG_BT_ERROR;
426 do_cleanups (cleanups);
427 }
428 }
429
430 if (retval != EXT_LANG_BT_ERROR)
431 {
432 if (val != NULL)
433 annotate_arg_value (value_type (val));
434
435 /* If the output is to the CLI, and the user option "set print
436 frame-arguments" is set to none, just output "...". */
437 if (! out->is_mi_like_p () && args_type == NO_VALUES)
438 out->field_string ("value", "...");
439 else
440 {
441 /* Otherwise, print the value for both MI and the CLI, except
442 for the case of MI_PRINT_NO_VALUES. */
443 if (args_type != NO_VALUES)
444 {
445 if (val == NULL)
446 {
447 gdb_assert (fa != NULL && fa->error != NULL);
448 out->field_fmt ("value",
449 _("<error reading variable: %s>"),
450 fa->error);
451 }
452 else if (py_print_value (out, val, opts, 0, args_type, language)
453 == EXT_LANG_BT_ERROR)
454 retval = EXT_LANG_BT_ERROR;
455 }
456 }
457
458 do_cleanups (cleanups);
459 }
460 }
461 CATCH (except, RETURN_MASK_ERROR)
462 {
463 gdbpy_convert_exception (except);
464 }
465 END_CATCH
466
467 return retval;
468 }
469
470 /* Helper function to loop over frame arguments provided by the
471 "frame_arguments" Python API. Elements in the iterator must
472 conform to the "Symbol Value" interface. ITER is the Python
473 iterable object, OUT is the output stream, ARGS_TYPE is an
474 enumerator describing the argument format, PRINT_ARGS_FIELD is a
475 flag which indicates if we output "ARGS=1" in MI output in commands
476 where both arguments and locals are printed, and FRAME is the
477 backing frame. Returns EXT_LANG_BT_ERROR on error, with any GDB
478 exceptions converted to a Python exception, or EXT_LANG_BT_OK on
479 success. */
480
481 static enum ext_lang_bt_status
482 enumerate_args (PyObject *iter,
483 struct ui_out *out,
484 enum ext_lang_frame_args args_type,
485 int print_args_field,
486 struct frame_info *frame)
487 {
488 struct value_print_options opts;
489
490 get_user_print_options (&opts);
491
492 if (args_type == CLI_SCALAR_VALUES)
493 {
494 /* True in "summary" mode, false otherwise. */
495 opts.summary = 1;
496 }
497
498 opts.deref_ref = 1;
499
500 TRY
501 {
502 annotate_frame_args ();
503 }
504 CATCH (except, RETURN_MASK_ALL)
505 {
506 gdbpy_convert_exception (except);
507 return EXT_LANG_BT_ERROR;
508 }
509 END_CATCH
510
511 /* Collect the first argument outside of the loop, so output of
512 commas in the argument output is correct. At the end of the
513 loop block collect another item from the iterator, and, if it is
514 not null emit a comma. */
515 gdbpy_ref item (PyIter_Next (iter));
516 if (item == NULL && PyErr_Occurred ())
517 return EXT_LANG_BT_ERROR;
518
519 while (item != NULL)
520 {
521 const struct language_defn *language;
522 gdb::unique_xmalloc_ptr<char> sym_name;
523 struct symbol *sym;
524 struct block *sym_block;
525 struct value *val;
526 enum ext_lang_bt_status success = EXT_LANG_BT_ERROR;
527
528 success = extract_sym (item.get (), &sym_name, &sym, &sym_block,
529 &language);
530 if (success == EXT_LANG_BT_ERROR)
531 return EXT_LANG_BT_ERROR;
532
533 success = extract_value (item.get (), &val);
534 if (success == EXT_LANG_BT_ERROR)
535 return EXT_LANG_BT_ERROR;
536
537 if (sym && out->is_mi_like_p ()
538 && ! mi_should_print (sym, MI_PRINT_ARGS))
539 continue;
540
541 /* If the object did not provide a value, read it using
542 read_frame_args and account for entry values, if any. */
543 if (val == NULL)
544 {
545 struct frame_arg arg, entryarg;
546
547 /* If there is no value, and also no symbol, set error and
548 exit. */
549 if (sym == NULL)
550 {
551 PyErr_SetString (PyExc_RuntimeError,
552 _("No symbol or value provided."));
553 return EXT_LANG_BT_ERROR;
554 }
555
556 TRY
557 {
558 read_frame_arg (sym, frame, &arg, &entryarg);
559 }
560 CATCH (except, RETURN_MASK_ALL)
561 {
562 gdbpy_convert_exception (except);
563 return EXT_LANG_BT_ERROR;
564 }
565 END_CATCH
566
567 /* The object has not provided a value, so this is a frame
568 argument to be read by GDB. In this case we have to
569 account for entry-values. */
570
571 if (arg.entry_kind != print_entry_values_only)
572 {
573 if (py_print_single_arg (out, NULL, &arg,
574 NULL, &opts,
575 args_type,
576 print_args_field,
577 NULL) == EXT_LANG_BT_ERROR)
578 {
579 xfree (arg.error);
580 xfree (entryarg.error);
581 return EXT_LANG_BT_ERROR;
582 }
583 }
584
585 if (entryarg.entry_kind != print_entry_values_no)
586 {
587 if (arg.entry_kind != print_entry_values_only)
588 {
589 TRY
590 {
591 out->text (", ");
592 out->wrap_hint (" ");
593 }
594 CATCH (except, RETURN_MASK_ALL)
595 {
596 xfree (arg.error);
597 xfree (entryarg.error);
598 gdbpy_convert_exception (except);
599 return EXT_LANG_BT_ERROR;
600 }
601 END_CATCH
602 }
603
604 if (py_print_single_arg (out, NULL, &entryarg, NULL, &opts,
605 args_type, print_args_field, NULL)
606 == EXT_LANG_BT_ERROR)
607 {
608 xfree (arg.error);
609 xfree (entryarg.error);
610 return EXT_LANG_BT_ERROR;
611 }
612 }
613
614 xfree (arg.error);
615 xfree (entryarg.error);
616 }
617 else
618 {
619 /* If the object has provided a value, we just print that. */
620 if (val != NULL)
621 {
622 if (py_print_single_arg (out, sym_name.get (), NULL, val, &opts,
623 args_type, print_args_field,
624 language) == EXT_LANG_BT_ERROR)
625 return EXT_LANG_BT_ERROR;
626 }
627 }
628
629 /* Collect the next item from the iterator. If
630 this is the last item, do not print the
631 comma. */
632 item.reset (PyIter_Next (iter));
633 if (item != NULL)
634 {
635 TRY
636 {
637 out->text (", ");
638 }
639 CATCH (except, RETURN_MASK_ALL)
640 {
641 gdbpy_convert_exception (except);
642 return EXT_LANG_BT_ERROR;
643 }
644 END_CATCH
645 }
646 else if (PyErr_Occurred ())
647 return EXT_LANG_BT_ERROR;
648
649 TRY
650 {
651 annotate_arg_end ();
652 }
653 CATCH (except, RETURN_MASK_ALL)
654 {
655 gdbpy_convert_exception (except);
656 return EXT_LANG_BT_ERROR;
657 }
658 END_CATCH
659 }
660
661 return EXT_LANG_BT_OK;
662 }
663
664
665 /* Helper function to loop over variables provided by the
666 "frame_locals" Python API. Elements in the iterable must conform
667 to the "Symbol Value" interface. ITER is the Python iterable
668 object, OUT is the output stream, INDENT is whether we should
669 indent the output (for CLI), ARGS_TYPE is an enumerator describing
670 the argument format, PRINT_ARGS_FIELD is flag which indicates
671 whether to output the ARGS field in the case of
672 -stack-list-variables and FRAME is the backing frame. Returns
673 EXT_LANG_BT_ERROR on error, with any GDB exceptions converted to a Python
674 exception, or EXT_LANG_BT_OK on success. */
675
676 static enum ext_lang_bt_status
677 enumerate_locals (PyObject *iter,
678 struct ui_out *out,
679 int indent,
680 enum ext_lang_frame_args args_type,
681 int print_args_field,
682 struct frame_info *frame)
683 {
684 struct value_print_options opts;
685
686 get_user_print_options (&opts);
687 opts.deref_ref = 1;
688
689 while (true)
690 {
691 const struct language_defn *language;
692 gdb::unique_xmalloc_ptr<char> sym_name;
693 struct value *val;
694 enum ext_lang_bt_status success = EXT_LANG_BT_ERROR;
695 struct symbol *sym;
696 struct block *sym_block;
697 int local_indent = 8 + (8 * indent);
698 struct cleanup *locals_cleanups;
699
700 gdbpy_ref item (PyIter_Next (iter));
701 if (item == NULL)
702 break;
703
704 locals_cleanups = make_cleanup (null_cleanup, NULL);
705
706 success = extract_sym (item.get (), &sym_name, &sym, &sym_block,
707 &language);
708 if (success == EXT_LANG_BT_ERROR)
709 {
710 do_cleanups (locals_cleanups);
711 goto error;
712 }
713
714 success = extract_value (item.get (), &val);
715 if (success == EXT_LANG_BT_ERROR)
716 {
717 do_cleanups (locals_cleanups);
718 goto error;
719 }
720
721 if (sym != NULL && out->is_mi_like_p ()
722 && ! mi_should_print (sym, MI_PRINT_LOCALS))
723 {
724 do_cleanups (locals_cleanups);
725 continue;
726 }
727
728 /* If the object did not provide a value, read it. */
729 if (val == NULL)
730 {
731 TRY
732 {
733 val = read_var_value (sym, sym_block, frame);
734 }
735 CATCH (except, RETURN_MASK_ERROR)
736 {
737 gdbpy_convert_exception (except);
738 do_cleanups (locals_cleanups);
739 goto error;
740 }
741 END_CATCH
742 }
743
744 /* With PRINT_NO_VALUES, MI does not emit a tuple normally as
745 each output contains only one field. The exception is
746 -stack-list-variables, which always provides a tuple. */
747 if (out->is_mi_like_p ())
748 {
749 if (print_args_field || args_type != NO_VALUES)
750 make_cleanup_ui_out_tuple_begin_end (out, NULL);
751 }
752 TRY
753 {
754 if (! out->is_mi_like_p ())
755 {
756 /* If the output is not MI we indent locals. */
757 out->spaces (local_indent);
758 }
759
760 out->field_string ("name", sym_name.get ());
761
762 if (! out->is_mi_like_p ())
763 out->text (" = ");
764 }
765 CATCH (except, RETURN_MASK_ERROR)
766 {
767 gdbpy_convert_exception (except);
768 do_cleanups (locals_cleanups);
769 goto error;
770 }
771 END_CATCH
772
773 if (args_type == MI_PRINT_SIMPLE_VALUES)
774 {
775 if (py_print_type (out, val) == EXT_LANG_BT_ERROR)
776 {
777 do_cleanups (locals_cleanups);
778 goto error;
779 }
780 }
781
782 /* CLI always prints values for locals. MI uses the
783 simple/no/all system. */
784 if (! out->is_mi_like_p ())
785 {
786 int val_indent = (indent + 1) * 4;
787
788 if (py_print_value (out, val, &opts, val_indent, args_type,
789 language) == EXT_LANG_BT_ERROR)
790 {
791 do_cleanups (locals_cleanups);
792 goto error;
793 }
794 }
795 else
796 {
797 if (args_type != NO_VALUES)
798 {
799 if (py_print_value (out, val, &opts, 0, args_type,
800 language) == EXT_LANG_BT_ERROR)
801 {
802 do_cleanups (locals_cleanups);
803 goto error;
804 }
805 }
806 }
807
808 do_cleanups (locals_cleanups);
809
810 TRY
811 {
812 out->text ("\n");
813 }
814 CATCH (except, RETURN_MASK_ERROR)
815 {
816 gdbpy_convert_exception (except);
817 goto error;
818 }
819 END_CATCH
820 }
821
822 if (!PyErr_Occurred ())
823 return EXT_LANG_BT_OK;
824
825 error:
826 return EXT_LANG_BT_ERROR;
827 }
828
829 /* Helper function for -stack-list-variables. Returns EXT_LANG_BT_ERROR on
830 error, or EXT_LANG_BT_OK on success. */
831
832 static enum ext_lang_bt_status
833 py_mi_print_variables (PyObject *filter, struct ui_out *out,
834 struct value_print_options *opts,
835 enum ext_lang_frame_args args_type,
836 struct frame_info *frame)
837 {
838 struct cleanup *old_chain;
839
840 gdbpy_ref args_iter (get_py_iter_from_func (filter, "frame_args"));
841 if (args_iter == NULL)
842 return EXT_LANG_BT_ERROR;
843
844 gdbpy_ref locals_iter (get_py_iter_from_func (filter, "frame_locals"));
845 if (locals_iter == NULL)
846 return EXT_LANG_BT_ERROR;
847
848 old_chain = make_cleanup_ui_out_list_begin_end (out, "variables");
849
850 if (args_iter != Py_None)
851 if (enumerate_args (args_iter.get (), out, args_type, 1, frame)
852 == EXT_LANG_BT_ERROR)
853 goto error;
854
855 if (locals_iter != Py_None)
856 if (enumerate_locals (locals_iter.get (), out, 1, args_type, 1, frame)
857 == EXT_LANG_BT_ERROR)
858 goto error;
859
860 do_cleanups (old_chain);
861 return EXT_LANG_BT_OK;
862
863 error:
864 do_cleanups (old_chain);
865 return EXT_LANG_BT_ERROR;
866 }
867
868 /* Helper function for printing locals. This function largely just
869 creates the wrapping tuple, and calls enumerate_locals. Returns
870 EXT_LANG_BT_ERROR on error, or EXT_LANG_BT_OK on success. */
871
872 static enum ext_lang_bt_status
873 py_print_locals (PyObject *filter,
874 struct ui_out *out,
875 enum ext_lang_frame_args args_type,
876 int indent,
877 struct frame_info *frame)
878 {
879 struct cleanup *old_chain;
880
881 gdbpy_ref locals_iter (get_py_iter_from_func (filter, "frame_locals"));
882 if (locals_iter == NULL)
883 return EXT_LANG_BT_ERROR;
884
885 old_chain = make_cleanup_ui_out_list_begin_end (out, "locals");
886
887 if (locals_iter != Py_None)
888 if (enumerate_locals (locals_iter.get (), out, indent, args_type,
889 0, frame) == EXT_LANG_BT_ERROR)
890 goto locals_error;
891
892 do_cleanups (old_chain);
893 return EXT_LANG_BT_OK;
894
895 locals_error:
896 do_cleanups (old_chain);
897 return EXT_LANG_BT_ERROR;
898 }
899
900 /* Helper function for printing frame arguments. This function
901 largely just creates the wrapping tuple, and calls enumerate_args.
902 Returns EXT_LANG_BT_ERROR on error, with any GDB exceptions converted to
903 a Python exception, or EXT_LANG_BT_OK on success. */
904
905 static enum ext_lang_bt_status
906 py_print_args (PyObject *filter,
907 struct ui_out *out,
908 enum ext_lang_frame_args args_type,
909 struct frame_info *frame)
910 {
911 struct cleanup *old_chain;
912
913 gdbpy_ref args_iter (get_py_iter_from_func (filter, "frame_args"));
914 if (args_iter == NULL)
915 return EXT_LANG_BT_ERROR;
916
917 old_chain = make_cleanup_ui_out_list_begin_end (out, "args");
918
919 TRY
920 {
921 annotate_frame_args ();
922 if (! out->is_mi_like_p ())
923 out->text (" (");
924 }
925 CATCH (except, RETURN_MASK_ALL)
926 {
927 gdbpy_convert_exception (except);
928 goto args_error;
929 }
930 END_CATCH
931
932 if (args_iter != Py_None)
933 if (enumerate_args (args_iter.get (), out, args_type, 0, frame)
934 == EXT_LANG_BT_ERROR)
935 goto args_error;
936
937 TRY
938 {
939 if (! out->is_mi_like_p ())
940 out->text (")");
941 }
942 CATCH (except, RETURN_MASK_ALL)
943 {
944 gdbpy_convert_exception (except);
945 goto args_error;
946 }
947 END_CATCH
948
949 do_cleanups (old_chain);
950 return EXT_LANG_BT_OK;
951
952 args_error:
953 do_cleanups (old_chain);
954 return EXT_LANG_BT_ERROR;
955 }
956
957 /* Print a single frame to the designated output stream, detecting
958 whether the output is MI or console, and formatting the output
959 according to the conventions of that protocol. FILTER is the
960 frame-filter associated with this frame. FLAGS is an integer
961 describing the various print options. The FLAGS variables is
962 described in "apply_frame_filter" function. ARGS_TYPE is an
963 enumerator describing the argument format. OUT is the output
964 stream to print, INDENT is the level of indention for this frame
965 (in the case of elided frames), and LEVELS_PRINTED is a hash-table
966 containing all the frames level that have already been printed.
967 If a frame level has been printed, do not print it again (in the
968 case of elided frames). Returns EXT_LANG_BT_ERROR on error, with any
969 GDB exceptions converted to a Python exception, or EXT_LANG_BT_COMPLETED
970 on success. It can also throw an exception RETURN_QUIT. */
971
972 static enum ext_lang_bt_status
973 py_print_frame (PyObject *filter, int flags,
974 enum ext_lang_frame_args args_type,
975 struct ui_out *out, int indent, htab_t levels_printed)
976 {
977 int has_addr = 0;
978 CORE_ADDR address = 0;
979 struct gdbarch *gdbarch = NULL;
980 struct frame_info *frame = NULL;
981 struct cleanup *cleanup_stack;
982 struct value_print_options opts;
983 int print_level, print_frame_info, print_args, print_locals;
984 gdb::unique_xmalloc_ptr<char> function_to_free;
985
986 /* Extract print settings from FLAGS. */
987 print_level = (flags & PRINT_LEVEL) ? 1 : 0;
988 print_frame_info = (flags & PRINT_FRAME_INFO) ? 1 : 0;
989 print_args = (flags & PRINT_ARGS) ? 1 : 0;
990 print_locals = (flags & PRINT_LOCALS) ? 1 : 0;
991
992 get_user_print_options (&opts);
993
994 /* Get the underlying frame. This is needed to determine GDB
995 architecture, and also, in the cases of frame variables/arguments to
996 read them if they returned filter object requires us to do so. */
997 gdbpy_ref py_inf_frame (PyObject_CallMethod (filter, "inferior_frame", NULL));
998 if (py_inf_frame == NULL)
999 return EXT_LANG_BT_ERROR;
1000
1001 frame = frame_object_to_frame_info (py_inf_frame.get ());
1002 if (frame == NULL)
1003 return EXT_LANG_BT_ERROR;
1004
1005 TRY
1006 {
1007 gdbarch = get_frame_arch (frame);
1008 }
1009 CATCH (except, RETURN_MASK_ERROR)
1010 {
1011 gdbpy_convert_exception (except);
1012 return EXT_LANG_BT_ERROR;
1013 }
1014 END_CATCH
1015
1016 /* stack-list-variables. */
1017 if (print_locals && print_args && ! print_frame_info)
1018 {
1019 if (py_mi_print_variables (filter, out, &opts,
1020 args_type, frame) == EXT_LANG_BT_ERROR)
1021 return EXT_LANG_BT_ERROR;
1022 return EXT_LANG_BT_COMPLETED;
1023 }
1024
1025 cleanup_stack = make_cleanup (null_cleanup, NULL);
1026
1027 /* -stack-list-locals does not require a
1028 wrapping frame attribute. */
1029 if (print_frame_info || (print_args && ! print_locals))
1030 make_cleanup_ui_out_tuple_begin_end (out, "frame");
1031
1032 if (print_frame_info)
1033 {
1034 /* Elided frames are also printed with this function (recursively)
1035 and are printed with indention. */
1036 if (indent > 0)
1037 {
1038 TRY
1039 {
1040 out->spaces (indent * 4);
1041 }
1042 CATCH (except, RETURN_MASK_ERROR)
1043 {
1044 gdbpy_convert_exception (except);
1045 do_cleanups (cleanup_stack);
1046 return EXT_LANG_BT_ERROR;
1047 }
1048 END_CATCH
1049 }
1050
1051 /* The address is required for frame annotations, and also for
1052 address printing. */
1053 if (PyObject_HasAttrString (filter, "address"))
1054 {
1055 gdbpy_ref paddr (PyObject_CallMethod (filter, "address", NULL));
1056
1057 if (paddr == NULL)
1058 {
1059 do_cleanups (cleanup_stack);
1060 return EXT_LANG_BT_ERROR;
1061 }
1062
1063 if (paddr != Py_None)
1064 {
1065 if (get_addr_from_python (paddr.get (), &address) < 0)
1066 {
1067 do_cleanups (cleanup_stack);
1068 return EXT_LANG_BT_ERROR;
1069 }
1070
1071 has_addr = 1;
1072 }
1073 }
1074 }
1075
1076 /* Print frame level. MI does not require the level if
1077 locals/variables only are being printed. */
1078 if ((print_frame_info || print_args) && print_level)
1079 {
1080 struct frame_info **slot;
1081 int level;
1082
1083 slot = (struct frame_info **) htab_find_slot (levels_printed,
1084 frame, INSERT);
1085 TRY
1086 {
1087 level = frame_relative_level (frame);
1088
1089 /* Check if this frame has already been printed (there are cases
1090 where elided synthetic dummy-frames have to 'borrow' the frame
1091 architecture from the eliding frame. If that is the case, do
1092 not print 'level', but print spaces. */
1093 if (*slot == frame)
1094 out->field_skip ("level");
1095 else
1096 {
1097 *slot = frame;
1098 annotate_frame_begin (print_level ? level : 0,
1099 gdbarch, address);
1100 out->text ("#");
1101 out->field_fmt_int (2, ui_left, "level",
1102 level);
1103 }
1104 }
1105 CATCH (except, RETURN_MASK_ERROR)
1106 {
1107 gdbpy_convert_exception (except);
1108 do_cleanups (cleanup_stack);
1109 return EXT_LANG_BT_ERROR;
1110 }
1111 END_CATCH
1112 }
1113
1114 if (print_frame_info)
1115 {
1116 /* Print address to the address field. If an address is not provided,
1117 print nothing. */
1118 if (opts.addressprint && has_addr)
1119 {
1120 TRY
1121 {
1122 annotate_frame_address ();
1123 out->field_core_addr ("addr", gdbarch, address);
1124 annotate_frame_address_end ();
1125 out->text (" in ");
1126 }
1127 CATCH (except, RETURN_MASK_ERROR)
1128 {
1129 gdbpy_convert_exception (except);
1130 do_cleanups (cleanup_stack);
1131 return EXT_LANG_BT_ERROR;
1132 }
1133 END_CATCH
1134 }
1135
1136 /* Print frame function name. */
1137 if (PyObject_HasAttrString (filter, "function"))
1138 {
1139 gdbpy_ref py_func (PyObject_CallMethod (filter, "function", NULL));
1140 const char *function = NULL;
1141
1142 if (py_func == NULL)
1143 {
1144 do_cleanups (cleanup_stack);
1145 return EXT_LANG_BT_ERROR;
1146 }
1147
1148 if (gdbpy_is_string (py_func.get ()))
1149 {
1150 function_to_free = python_string_to_host_string (py_func.get ());
1151
1152 if (function_to_free == NULL)
1153 {
1154 do_cleanups (cleanup_stack);
1155 return EXT_LANG_BT_ERROR;
1156 }
1157
1158 function = function_to_free.get ();
1159 }
1160 else if (PyLong_Check (py_func.get ()))
1161 {
1162 CORE_ADDR addr;
1163 struct bound_minimal_symbol msymbol;
1164
1165 if (get_addr_from_python (py_func.get (), &addr) < 0)
1166 {
1167 do_cleanups (cleanup_stack);
1168 return EXT_LANG_BT_ERROR;
1169 }
1170
1171 msymbol = lookup_minimal_symbol_by_pc (addr);
1172 if (msymbol.minsym != NULL)
1173 function = MSYMBOL_PRINT_NAME (msymbol.minsym);
1174 }
1175 else if (py_func != Py_None)
1176 {
1177 PyErr_SetString (PyExc_RuntimeError,
1178 _("FrameDecorator.function: expecting a " \
1179 "String, integer or None."));
1180 do_cleanups (cleanup_stack);
1181 return EXT_LANG_BT_ERROR;
1182 }
1183
1184 TRY
1185 {
1186 annotate_frame_function_name ();
1187 if (function == NULL)
1188 out->field_skip ("func");
1189 else
1190 out->field_string ("func", function);
1191 }
1192 CATCH (except, RETURN_MASK_ERROR)
1193 {
1194 gdbpy_convert_exception (except);
1195 do_cleanups (cleanup_stack);
1196 return EXT_LANG_BT_ERROR;
1197 }
1198 END_CATCH
1199 }
1200 }
1201
1202
1203 /* Frame arguments. Check the result, and error if something went
1204 wrong. */
1205 if (print_args)
1206 {
1207 if (py_print_args (filter, out, args_type, frame) == EXT_LANG_BT_ERROR)
1208 {
1209 do_cleanups (cleanup_stack);
1210 return EXT_LANG_BT_ERROR;
1211 }
1212 }
1213
1214 /* File name/source/line number information. */
1215 if (print_frame_info)
1216 {
1217 TRY
1218 {
1219 annotate_frame_source_begin ();
1220 }
1221 CATCH (except, RETURN_MASK_ERROR)
1222 {
1223 gdbpy_convert_exception (except);
1224 do_cleanups (cleanup_stack);
1225 return EXT_LANG_BT_ERROR;
1226 }
1227 END_CATCH
1228
1229 if (PyObject_HasAttrString (filter, "filename"))
1230 {
1231 gdbpy_ref py_fn (PyObject_CallMethod (filter, "filename", NULL));
1232
1233 if (py_fn == NULL)
1234 {
1235 do_cleanups (cleanup_stack);
1236 return EXT_LANG_BT_ERROR;
1237 }
1238
1239 if (py_fn != Py_None)
1240 {
1241 gdb::unique_xmalloc_ptr<char>
1242 filename (python_string_to_host_string (py_fn.get ()));
1243
1244 if (filename == NULL)
1245 {
1246 do_cleanups (cleanup_stack);
1247 return EXT_LANG_BT_ERROR;
1248 }
1249
1250 TRY
1251 {
1252 out->wrap_hint (" ");
1253 out->text (" at ");
1254 annotate_frame_source_file ();
1255 out->field_string ("file", filename.get ());
1256 annotate_frame_source_file_end ();
1257 }
1258 CATCH (except, RETURN_MASK_ERROR)
1259 {
1260 gdbpy_convert_exception (except);
1261 do_cleanups (cleanup_stack);
1262 return EXT_LANG_BT_ERROR;
1263 }
1264 END_CATCH
1265 }
1266 }
1267
1268 if (PyObject_HasAttrString (filter, "line"))
1269 {
1270 gdbpy_ref py_line (PyObject_CallMethod (filter, "line", NULL));
1271 int line;
1272
1273 if (py_line == NULL)
1274 {
1275 do_cleanups (cleanup_stack);
1276 return EXT_LANG_BT_ERROR;
1277 }
1278
1279 if (py_line != Py_None)
1280 {
1281 line = PyLong_AsLong (py_line.get ());
1282 if (PyErr_Occurred ())
1283 {
1284 do_cleanups (cleanup_stack);
1285 return EXT_LANG_BT_ERROR;
1286 }
1287
1288 TRY
1289 {
1290 out->text (":");
1291 annotate_frame_source_line ();
1292 out->field_int ("line", line);
1293 }
1294 CATCH (except, RETURN_MASK_ERROR)
1295 {
1296 gdbpy_convert_exception (except);
1297 do_cleanups (cleanup_stack);
1298 return EXT_LANG_BT_ERROR;
1299 }
1300 END_CATCH
1301 }
1302 }
1303 }
1304
1305 /* For MI we need to deal with the "children" list population of
1306 elided frames, so if MI output detected do not send newline. */
1307 if (! out->is_mi_like_p ())
1308 {
1309 TRY
1310 {
1311 annotate_frame_end ();
1312 out->text ("\n");
1313 }
1314 CATCH (except, RETURN_MASK_ERROR)
1315 {
1316 gdbpy_convert_exception (except);
1317 do_cleanups (cleanup_stack);
1318 return EXT_LANG_BT_ERROR;
1319 }
1320 END_CATCH
1321 }
1322
1323 if (print_locals)
1324 {
1325 if (py_print_locals (filter, out, args_type, indent,
1326 frame) == EXT_LANG_BT_ERROR)
1327 {
1328 do_cleanups (cleanup_stack);
1329 return EXT_LANG_BT_ERROR;
1330 }
1331 }
1332
1333 {
1334 /* Finally recursively print elided frames, if any. */
1335 gdbpy_ref elided (get_py_iter_from_func (filter, "elided"));
1336 if (elided == NULL)
1337 {
1338 do_cleanups (cleanup_stack);
1339 return EXT_LANG_BT_ERROR;
1340 }
1341
1342 if (elided != Py_None)
1343 {
1344 PyObject *item;
1345
1346 make_cleanup_ui_out_list_begin_end (out, "children");
1347
1348 if (! out->is_mi_like_p ())
1349 indent++;
1350
1351 while ((item = PyIter_Next (elided.get ())))
1352 {
1353 gdbpy_ref item_ref (item);
1354
1355 enum ext_lang_bt_status success = py_print_frame (item, flags,
1356 args_type, out,
1357 indent,
1358 levels_printed);
1359
1360 if (success == EXT_LANG_BT_ERROR)
1361 {
1362 do_cleanups (cleanup_stack);
1363 return EXT_LANG_BT_ERROR;
1364 }
1365 }
1366 if (item == NULL && PyErr_Occurred ())
1367 {
1368 do_cleanups (cleanup_stack);
1369 return EXT_LANG_BT_ERROR;
1370 }
1371 }
1372 }
1373
1374 do_cleanups (cleanup_stack);
1375 return EXT_LANG_BT_COMPLETED;
1376 }
1377
1378 /* Helper function to initiate frame filter invocation at starting
1379 frame FRAME. */
1380
1381 static PyObject *
1382 bootstrap_python_frame_filters (struct frame_info *frame,
1383 int frame_low, int frame_high)
1384 {
1385 gdbpy_ref frame_obj (frame_info_to_frame_object (frame));
1386 if (frame_obj == NULL)
1387 return NULL;
1388
1389 gdbpy_ref module (PyImport_ImportModule ("gdb.frames"));
1390 if (module == NULL)
1391 return NULL;
1392
1393 gdbpy_ref sort_func (PyObject_GetAttrString (module.get (),
1394 "execute_frame_filters"));
1395 if (sort_func == NULL)
1396 return NULL;
1397
1398 gdbpy_ref py_frame_low (PyInt_FromLong (frame_low));
1399 if (py_frame_low == NULL)
1400 return NULL;
1401
1402 gdbpy_ref py_frame_high (PyInt_FromLong (frame_high));
1403 if (py_frame_high == NULL)
1404 return NULL;
1405
1406 gdbpy_ref iterable (PyObject_CallFunctionObjArgs (sort_func.get (),
1407 frame_obj.get (),
1408 py_frame_low.get (),
1409 py_frame_high.get (),
1410 NULL));
1411 if (iterable == NULL)
1412 return NULL;
1413
1414 if (iterable != Py_None)
1415 return PyObject_GetIter (iterable.get ());
1416 else
1417 return iterable.release ();
1418 }
1419
1420 /* This is the only publicly exported function in this file. FRAME
1421 is the source frame to start frame-filter invocation. FLAGS is an
1422 integer holding the flags for printing. The following elements of
1423 the FRAME_FILTER_FLAGS enum denotes the make-up of FLAGS:
1424 PRINT_LEVEL is a flag indicating whether to print the frame's
1425 relative level in the output. PRINT_FRAME_INFO is a flag that
1426 indicates whether this function should print the frame
1427 information, PRINT_ARGS is a flag that indicates whether to print
1428 frame arguments, and PRINT_LOCALS, likewise, with frame local
1429 variables. ARGS_TYPE is an enumerator describing the argument
1430 format, OUT is the output stream to print. FRAME_LOW is the
1431 beginning of the slice of frames to print, and FRAME_HIGH is the
1432 upper limit of the frames to count. Returns EXT_LANG_BT_ERROR on error,
1433 or EXT_LANG_BT_COMPLETED on success. */
1434
1435 enum ext_lang_bt_status
1436 gdbpy_apply_frame_filter (const struct extension_language_defn *extlang,
1437 struct frame_info *frame, int flags,
1438 enum ext_lang_frame_args args_type,
1439 struct ui_out *out, int frame_low, int frame_high)
1440 {
1441 struct gdbarch *gdbarch = NULL;
1442 enum ext_lang_bt_status success = EXT_LANG_BT_ERROR;
1443
1444 if (!gdb_python_initialized)
1445 return EXT_LANG_BT_NO_FILTERS;
1446
1447 TRY
1448 {
1449 gdbarch = get_frame_arch (frame);
1450 }
1451 CATCH (except, RETURN_MASK_ALL)
1452 {
1453 /* Let gdb try to print the stack trace. */
1454 return EXT_LANG_BT_NO_FILTERS;
1455 }
1456 END_CATCH
1457
1458 gdbpy_enter enter_py (gdbarch, current_language);
1459
1460 gdbpy_ref iterable (bootstrap_python_frame_filters (frame, frame_low,
1461 frame_high));
1462
1463 if (iterable == NULL)
1464 {
1465 /* Normally if there is an error GDB prints the exception,
1466 abandons the backtrace and exits. The user can then call "bt
1467 no-filters", and get a default backtrace (it would be
1468 confusing to automatically start a standard backtrace halfway
1469 through a Python filtered backtrace). However in the case
1470 where GDB cannot initialize the frame filters (most likely
1471 due to incorrect auto-load paths), GDB has printed nothing.
1472 In this case it is OK to print the default backtrace after
1473 printing the error message. GDB returns EXT_LANG_BT_NO_FILTERS
1474 here to signify there are no filters after printing the
1475 initialization error. This return code will trigger a
1476 default backtrace. */
1477
1478 gdbpy_print_stack ();
1479 return EXT_LANG_BT_NO_FILTERS;
1480 }
1481
1482 /* If iterable is None, then there are no frame filters registered.
1483 If this is the case, defer to default GDB printing routines in MI
1484 and CLI. */
1485 if (iterable == Py_None)
1486 return EXT_LANG_BT_NO_FILTERS;
1487
1488 htab_up levels_printed (htab_create (20,
1489 htab_hash_pointer,
1490 htab_eq_pointer,
1491 NULL));
1492
1493 while (true)
1494 {
1495 gdbpy_ref item (PyIter_Next (iterable.get ()));
1496
1497 if (item == NULL)
1498 {
1499 if (PyErr_Occurred ())
1500 {
1501 gdbpy_print_stack ();
1502 return EXT_LANG_BT_ERROR;
1503 }
1504 break;
1505 }
1506
1507 success = py_print_frame (item.get (), flags, args_type, out, 0,
1508 levels_printed.get ());
1509
1510 /* Do not exit on error printing a single frame. Print the
1511 error and continue with other frames. */
1512 if (success == EXT_LANG_BT_ERROR)
1513 gdbpy_print_stack ();
1514 }
1515
1516 return success;
1517 }
This page took 0.085748 seconds and 5 git commands to generate.