aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
AgeCommit message (Collapse)AuthorFilesLines
2017-02-14PR python/13598 - add before_prompt eventTom Tromey3-0/+9
This adds an event that is emitted just before GDB presents a prompt to the user. This provides Python code a way to react to whatever changes might have been made by the previous command. For example, in my GUI I use this to track changes to the selected frame and reflect them in the UI. Built and regtested on x86-64 Fedora 23. gdb/ChangeLog 2017-02-14 Tom Tromey <tom@tromey.com> PR python/13598: * python/python.c (gdbpy_before_prompt_hook): Emit before_prompt event. * python/py-evts.c (gdbpy_initialize_py_events): Add before_prompt registry. * python/py-events.h (events_object) <before_prompt>: New field. gdb/doc/ChangeLog 2017-02-14 Tom Tromey <tom@tromey.com> PR python/13598: * python.texi (Events In Python): Document events.before_prompt. gdb/testsuite/ChangeLog 2017-02-14 Tom Tromey <tom@tromey.com> PR python/13598: * gdb.python/py-events.exp: Add before_prompt event tests.
2017-02-14python: Implement btrace Python bindings for record history.Tim Wiederhake7-0/+1173
This patch implements the gdb.Record Python object methods and fields for record target btrace. Also, implement a stub for record target full. Signed-off-by: Tim Wiederhake <tim.wiederhake@intel.com> gdb/ChangeLog: * Makefile.in (SUBDIR_PYTHON_OBS): Add py-record-btrace.o, py-record-full.o. (SUBDIR_PYTHON_SRCS): Add py-record-btrace.c, py-record-full.c. * python/py-record-btrace.c, python/py-record-btrace.h, python/py-record-full.c, python/py-record-full.h: New file. * python/py-record.c: Add include for py-record-btrace.h and py-record-full.h. (recpy_method, recpy_format, recpy_goto, recpy_replay_position, recpy_instruction_history, recpy_function_call_history, recpy_begin, recpy_end): Use functions from py-record-btrace.c and py-record-full.c. * python/python-internal.h (PyInt_FromSsize_t, PyInt_AsSsize_t): New definition. (gdbpy_initialize_btrace): New export. * python/python.c (_initialize_python): Add gdbpy_initialize_btrace. Change-Id: I8bd893672ffc7e619cc1386767897249e125973a
2017-02-14python: Create Python bindings for record history.Tim Wiederhake3-0/+245
This patch adds three new functions to the gdb module in Python: - start_recording - stop_recording - current_recording start_recording and current_recording return an object of the new type gdb.Record, which can be used to access the recorded data. Signed-off-by: Tim Wiederhake <tim.wiederhake@intel.com> gdb/ChangeLog * Makefile.in (SUBDIR_PYTHON_OBS): Add python/py-record.o. (SUBDIR_PYTHON_SRCS): Add python/py-record.c. * python/py-record.c: New file. * python/python-internal.h (gdbpy_start_recording, gdbpy_current_recording, gdpy_stop_recording, gdbpy_initialize_record): New export. * python/python.c (_initialize_python): Add gdbpy_initialize_record. (python_GdbMethods): Add gdbpy_start_recording, gdbpy_current_recording and gdbpy_stop_recording. Change-Id: I772aa9aa068621443f10a330b11dc7dc9a63face
2017-02-10Remove unnecessary local variablesTom Tromey2-2/+0
I found an unused local variables in a couple of places in the Python code; this removes them. gdb/ChangeLog 2017-02-10 Tom Tromey <tom@tromey.com> * python/py-value.c (valpy_richcompare_throw): Remove unnecessary "cleanup" local. * python/py-type.c (typy_legacy_template_argument): Remove unnecessary "cleanup" local.
2017-02-10Remove some gotos from PythonTom Tromey2-99/+107
This patch slightly refactors a couple of spots in the Python code to avoid some gotos. gdb/ChangeLog 2017-02-10 Tom Tromey <tom@tromey.com> * python/python.c (do_start_initialization): New function, from _initialize_python. (_initialize_python): Call do_start_initialization. * python/py-linetable.c (ltpy_iternext): Use explicit returns, not goto.
2017-02-10Change one more spot to use gdbpy_refTom Tromey1-7/+8
This patch changes one more spot in the Python layer to use gdbpy_ref. gdb/ChangeLog 2017-02-10 Tom Tromey <tom@tromey.com> * python/py-prettyprint.c (pretty_print_one_value): Use gdbpy_ref.
2017-02-10Use gdbpy_ref to simplify some logicTom Tromey10-116/+72
This uses the new gdbpy_ref template to simplify logic in various parts of the Python layer; for example removing repeated error code or removing gotos. gdb/ChangeLog 2017-02-10 Tom Tromey <tom@tromey.com> * python/py-cmd.c (cmdpy_destroyer): Use gdbpy_ref. * python/py-breakpoint.c (gdbpy_breakpoint_deleted): Use gdbpy_ref. * python/py-type.c (field_new): Use gdbpy_ref. * python/py-symtab.c (symtab_and_line_to_sal_object): Use gdbpy_ref. * python/py-progspace.c (pspy_new): Use gdbpy_ref. (py_free_pspace): Likewise. (pspace_to_pspace_object): Likewise. * python/py-objfile.c (objfpy_new): Use gdbpy_ref. (py_free_objfile): Likewise. (objfile_to_objfile_object): Likewise. * python/py-inferior.c (delete_thread_object): Use gdbpy_ref. (infpy_read_memory): Likewise. (py_free_inferior): Likewise. * python/py-evtregistry.c (create_eventregistry_object): Use gdbpy_ref. * python/py-event.c (create_event_object): Use gdbpy_ref.
2017-02-10Turn gdbpy_ref into a templateTom Tromey28-228/+236
This turns gdbpy_ref into a template class, so that it can be used to wrap subclasses of PyObject. The default argument remains PyObject; and this necessitated renaming uses of "gdbpy_ref" to "gdbpy_ref<>". gdb/ChangeLog 2017-02-10 Tom Tromey <tom@tromey.com> * python/py-ref.h (gdbpy_ref_policy): Now a template. (gdbpy_ref): Now a template; allow subclasses of PyObject to be used. * python/py-arch.c, python/py-bpevent.c, python/py-breakpoint.c, python/py-cmd.c, python/py-continueevent.c, python/py-event.c, python/py-exitedevent.c, python/py-finishbreakpoint.c, python/py-framefilter.c, python/py-function.c, python/py-inferior.c, python/py-infevents.c, python/py-linetable.c, python/py-newobjfileevent.c, python/py-param.c, python/py-prettyprint.c, python/py-ref.h, python/py-signalevent.c, python/py-stopevent.c, python/py-symbol.c, python/py-threadevent.c, python/py-type.c, python/py-unwind.c, python/py-utils.c, python/py-value.c, python/py-varobj.c, python/py-xmethods.c, python/python.c, varobj.c: Change gdbpy_ref to gdbpy_ref<>.
2017-02-10Remove some ui_out-related cleanups from PythonTom Tromey1-156/+53
This patch introduces a bit of infrastructure -- namely, a minimal std::optional analogue called gdb::optional, and an RAII template class that works like make_cleanup_ui_out_tuple_begin_end or make_cleanup_ui_out_list_begin_end -- and then uses these in the Python code. This removes a number of cleanups and generally simplifies this code. std::optional is only available in C++17. Normally I would have had this code check __cplusplus, but my gcc apparently isn't new enough to find <optional>, even with -std=c++1z; so, because I could not test it, the patch does not do this. gdb/ChangeLog 2017-02-10 Tom Tromey <tom@tromey.com> * ui-out.h (ui_out_emit_type): New class. (ui_out_emit_tuple, ui_out_emit_list): New typedefs. * python/py-framefilter.c (py_print_single_arg): Use gdb::optional and ui_out_emit_tuple. (enumerate_locals): Likewise. (py_mi_print_variables, py_print_locals, py_print_args): Use ui_out_emit_list. (py_print_frame): Use gdb::optional, ui_out_emit_tuple, ui_out_emit_list. * common/gdb_optional.h: New file.
2017-02-02Eliminate make_cleanup_ui_file_delete / make ui_file a class hierarchyPedro Alves7-102/+41
This patch starts from the desire to eliminate make_cleanup_ui_file_delete, but then goes beyond. It makes ui_file & friends a real C++ class hierarchy, and switches temporary ui_file-like objects to stack-based allocation. - mem_fileopen -> string_file mem_fileopen is replaced with a new string_file class that is treated as a value class created on the stack. This alone eliminates most make_cleanup_ui_file_delete calls, and, simplifies code a whole lot (diffstat shows around 1k loc dropped.) string_file's internal buffer is a std::string, thus the "string" in the name. This simplifies the implementation much, compared to mem_fileopen, which managed growing its internal buffer manually. - ui_file_as_string, ui_file_strdup, ui_file_obsavestring all gone The new string_file class has a string() method that provides direct writable access to the internal std::string buffer. This replaced ui_file_as_string, which forced a copy of the same data the stream had inside. With direct access via a writable reference, we can instead move the string out of the string_stream, avoiding deep string copying. Related, ui_file_xstrdup calls are replaced with xstrdup'ping the stream's string, and ui_file_obsavestring is replaced by obstack_copy0. With all those out of the way, getting rid of the weird ui_file_put mechanism was possible. - New ui_file::printf, ui_file::puts, etc. methods These simplify / clarify client code. I considered splitting client-code changes, like these, e.g.: - stb = mem_fileopen (); - fprintf_unfiltered (stb, "%s%s%s", - _("The valid values are:\n"), - regdesc, - _("The default is \"std\".")); + string_file stb; + stb.printf ("%s%s%s", + _("The valid values are:\n"), + regdesc, + _("The default is \"std\".")); In two steps, with the first step leaving fprintf_unfiltered (etc.) calls in place, and only afterwards do a pass to change all those to call stb.printf etc.. I didn't do that split, because (when I tried), it turned out to be pointless make-work: the first pass would have to touch the fprintf_unfiltered line anyway, to replace "stb" with "&stb". - gdb_fopen replaced with stack-based objects This avoids the need for cleanups or unique_ptr's. I.e., this: struct ui_file *file = gdb_fopen (filename, "w"); if (filename == NULL) perror_with_name (filename); cleanups = make_cleanup_ui_file_delete (file); // use file. do_cleanups (cleanups); is replaced with this: stdio_file file; if (!file.open (filename, "w")) perror_with_name (filename); // use file. - odd contorsions in null_file_write / null_file_fputs around when to call to_fputs / to_write eliminated. - Global null_stream object A few places that were allocating a ui_file in order to print to "nowhere" are adjusted to instead refer to a new 'null_stream' global stream. - TUI's tui_sfileopen eliminated. TUI's ui_file much simplified The TUI's ui_file was serving a dual purpose. It supported being used as string buffer, and supported being backed by a stdio FILE. The string buffer part is gone, replaced by using of string_file. The 'FILE *' support is now much simplified, by making the TUI's ui_file inherit from stdio_file. gdb/ChangeLog: 2017-02-02 Pedro Alves <palves@redhat.com> * ada-lang.c (type_as_string): Use string_file. * ada-valprint.c (ada_print_floating): Use string_file. * ada-varobj.c (ada_varobj_scalar_image) (ada_varobj_get_value_image): Use string_file. * aix-thread.c (aix_thread_extra_thread_info): Use string_file. * arm-tdep.c (_initialize_arm_tdep): Use string_printf. * breakpoint.c (update_inserted_breakpoint_locations) (insert_breakpoint_locations, reattach_breakpoints) (print_breakpoint_location, print_one_detail_ranged_breakpoint) (print_it_watchpoint): Use string_file. (save_breakpoints): Use stdio_file. * c-exp.y (oper): Use string_file. * cli/cli-logging.c (set_logging_redirect): Use ui_file_up and tee_file. (pop_output_files): Use delete. (handle_redirections): Use stdio_file and tee_file. * cli/cli-setshow.c (do_show_command): Use string_file. * compile/compile-c-support.c (c_compute_program): Use string_file. * compile/compile-c-symbols.c (generate_vla_size): Take a 'string_file &' instead of a 'ui_file *'. (generate_c_for_for_one_variable): Take a 'string_file &' instead of a 'ui_file *'. Use string_file. (generate_c_for_variable_locations): Take a 'string_file &' instead of a 'ui_file *'. * compile/compile-internal.h (generate_c_for_for_one_variable): Take a 'string_file &' instead of a 'ui_file *'. * compile/compile-loc2c.c (push, pushf, unary, binary) (print_label, pushf_register_address, pushf_register) (do_compile_dwarf_expr_to_c): Take a 'string_file &' instead of a 'ui_file *'. Adjust. * compile/compile.c (compile_to_object): Use string_file. * compile/compile.h (compile_dwarf_expr_to_c) (compile_dwarf_bounds_to_c): Take a 'string_file &' instead of a 'ui_file *'. * cp-support.c (inspect_type): Use string_file and obstack_copy0. (replace_typedefs_qualified_name): Use string_file and obstack_copy0. * disasm.c (gdb_pretty_print_insn): Use string_file. (gdb_disassembly): Adjust reference the null_stream global. (do_ui_file_delete): Delete. (gdb_insn_length): Use null_stream. * dummy-frame.c (maintenance_print_dummy_frames): Use stdio_file. * dwarf2loc.c (dwarf2_compile_property_to_c) (locexpr_generate_c_location, loclist_generate_c_location): Take a 'string_file &' instead of a 'ui_file *'. * dwarf2loc.h (dwarf2_compile_property_to_c): Likewise. * dwarf2read.c (do_ui_file_peek_last): Delete. (dwarf2_compute_name): Use string_file. * event-top.c (gdb_setup_readline): Use stdio_file. * gdbarch.sh (verify_gdbarch): Use string_file. * gdbtypes.c (safe_parse_type): Use null_stream. * guile/scm-breakpoint.c (gdbscm_breakpoint_commands): Use string_file. * guile/scm-disasm.c (gdbscm_print_insn_from_port): Take a 'string_file *' instead of a 'ui_file *'. (gdbscm_arch_disassemble): Use string_file. * guile/scm-frame.c (frscm_print_frame_smob): Use string_file. * guile/scm-ports.c (class ioscm_file_port): Now a class that inherits from ui_file. (ioscm_file_port_delete, ioscm_file_port_rewind) (ioscm_file_port_put): Delete. (ioscm_file_port_write): Rename to ... (ioscm_file_port::write): ... this. Remove file_port_magic checks. (ioscm_file_port_new): Delete. (ioscm_with_output_to_port_worker): Use ioscm_file_port and ui_file_up. * guile/scm-type.c (tyscm_type_name): Use string_file. * guile/scm-value.c (vlscm_print_value_smob, gdbscm_value_print): Use string_file. * infcmd.c (print_return_value_1): Use string_file. * infrun.c (print_target_wait_results): Use string_file. * language.c (add_language): Use string_file. * location.c (explicit_to_string_internal): Use string_file. * main.c (captured_main_1): Use null_file. * maint.c (maintenance_print_architecture): Use stdio_file. * mi/mi-cmd-stack.c (list_arg_or_local): Use string_file. * mi/mi-common.h (struct mi_interp) <out, err, log, targ, event_channel>: Change type to mi_console_file pointer. * mi/mi-console.c (mi_console_file_fputs, mi_console_file_flush) (mi_console_file_delete): Delete. (struct mi_console_file): Delete. (mi_console_file_magic): Delete. (mi_console_file_new): Delete. (mi_console_file::mi_console_file): New. (mi_console_file_delete): Delete. (mi_console_file_fputs): Delete. (mi_console_file::write): New. (mi_console_raw_packet): Delete. (mi_console_file::flush): New. (mi_console_file_flush): Delete. (mi_console_set_raw): Rename to ... (mi_console_file::set_raw): ... this. * mi/mi-console.h (class mi_console_file): New class. (mi_console_file_new, mi_console_set_raw): Delete. * mi/mi-interp.c (mi_interpreter_init): Use mi_console_file. (mi_set_logging): Use delete and tee_file. Adjust. * mi/mi-main.c (output_register): Use string_file. (mi_cmd_data_evaluate_expression): Use string_file. (mi_cmd_data_read_memory): Use string_file. (mi_cmd_execute, print_variable_or_computed): Use string_file. * mi/mi-out.c (mi_ui_out::main_stream): New. (mi_ui_out::rewind): Use main_stream and string_file. (mi_ui_out::put): Use main_stream and string_file. (mi_ui_out::mi_ui_out): Remove 'stream' parameter. Allocate a 'string_file' instead. (mi_out_new): Don't allocate a mem_fileopen stream here. * mi/mi-out.h (mi_ui_out::mi_ui_out): Remove 'stream' parameter. (mi_ui_out::main_stream): Declare method. * printcmd.c (eval_command): Use string_file. * psymtab.c (maintenance_print_psymbols): Use stdio_file. * python/py-arch.c (archpy_disassemble): Use string_file. * python/py-breakpoint.c (bppy_get_commands): Use string_file. * python/py-frame.c (frapy_str): Use string_file. * python/py-framefilter.c (py_print_type, py_print_single_arg): Use string_file. * python/py-type.c (typy_str): Use string_file. * python/py-unwind.c (unwind_infopy_str): Use string_file. * python/py-value.c (valpy_str): Use string_file. * record-btrace.c (btrace_insn_history): Use string_file. * regcache.c (regcache_print): Use stdio_file. * reggroups.c (maintenance_print_reggroups): Use stdio_file. * remote.c (escape_buffer): Use string_file. * rust-lang.c (rust_get_disr_info): Use string_file. * serial.c (serial_open_ops_1): Use stdio_file. (do_serial_close): Use delete. * stack.c (print_frame_arg): Use string_file. (print_frame_args): Remove local mem_fileopen stream, not used. (print_frame): Use string_file. * symmisc.c (maintenance_print_symbols): Use stdio_file. * symtab.h (struct symbol_computed_ops) <generate_c_location>: Take a 'string_file *' instead of a 'ui_file *'. * top.c (new_ui): Use stdio_file and stderr_file. (free_ui): Use delete. (execute_command_to_string): Use string_file. (quit_confirm): Use string_file. * tracepoint.c (collection_list::append_exp): Use string_file. * tui/tui-disasm.c (tui_disassemble): Use string_file. * tui/tui-file.c: Don't include "ui-file.h". (enum streamtype, struct tui_stream): Delete. (tui_file_new, tui_file_delete, tui_fileopen, tui_sfileopen) (tui_file_isatty, tui_file_rewind, tui_file_put): Delete. (tui_file::tui_file): New method. (tui_file_fputs): Delete. (tui_file_get_strbuf): Delete. (tui_file::puts): New method. (tui_file_adjust_strbuf): Delete. (tui_file_flush): Delete. (tui_file::flush): New method. * tui/tui-file.h: Tweak intro comment. Include ui-file.h. (tui_fileopen, tui_sfileopen, tui_file_get_strbuf) (tui_file_adjust_strbuf): Delete declarations. (class tui_file): New class. * tui/tui-io.c (tui_initialize_io): Use tui_file. * tui/tui-regs.c (tui_restore_gdbout): Use delete. (tui_register_format): Use string_stream. * tui/tui-stack.c (tui_make_status_line): Use string_file. (tui_get_function_from_frame): Use string_file. * typeprint.c (type_to_string): Use string_file. * ui-file.c (struct ui_file, ui_file_magic, ui_file_new): Delete. (null_stream): New global. (ui_file_delete): Delete. (ui_file::ui_file): New. (null_file_isatty): Delete. (ui_file::~ui_file): New. (null_file_rewind): Delete. (ui_file::printf): New. (null_file_put): Delete. (null_file_flush): Delete. (ui_file::putstr): New. (null_file_write): Delete. (ui_file::putstrn): New. (null_file_read): Delete. (ui_file::putc): New. (null_file_fputs): Delete. (null_file_write_async_safe): Delete. (ui_file::vprintf): New. (null_file_delete): Delete. (null_file::write): New. (null_file_fseek): Delete. (null_file::puts): New. (ui_file_data): Delete. (null_file::write_async_safe): New. (gdb_flush, ui_file_isatty): Adjust. (ui_file_put, ui_file_rewind): Delete. (ui_file_write): Adjust. (ui_file_write_for_put): Delete. (ui_file_write_async_safe, ui_file_read): Adjust. (ui_file_fseek): Delete. (fputs_unfiltered): Adjust. (set_ui_file_flush, set_ui_file_isatty, set_ui_file_rewind) (set_ui_file_put, set_ui_file_write, set_ui_file_write_async_safe) (set_ui_file_read, set_ui_file_fputs, set_ui_file_fseek) (set_ui_file_data): Delete. (string_file::~string_file, string_file::write) (struct accumulated_ui_file, do_ui_file_xstrdup, ui_file_xstrdup) (do_ui_file_as_string, ui_file_as_string): Delete. (do_ui_file_obsavestring, ui_file_obsavestring): Delete. (struct mem_file): Delete. (mem_file_new): Delete. (stdio_file::stdio_file): New. (mem_file_delete): Delete. (stdio_file::stdio_file): New. (mem_fileopen): Delete. (stdio_file::~stdio_file): New. (mem_file_rewind): Delete. (stdio_file::set_stream): New. (mem_file_put): Delete. (stdio_file::open): New. (mem_file_write): Delete. (stdio_file_magic, struct stdio_file): Delete. (stdio_file_new, stdio_file_delete, stdio_file_flush): Delete. (stdio_file::flush): New. (stdio_file_read): Rename to ... (stdio_file::read): ... this. Adjust. (stdio_file_write): Rename to ... (stdio_file::write): ... this. Adjust. (stdio_file_write_async_safe): Rename to ... (stdio_file::write_async_safe) ... this. Adjust. (stdio_file_fputs): Rename to ... (stdio_file::puts) ... this. Adjust. (stdio_file_isatty): Delete. (stdio_file_fseek): Delete. (stdio_file::isatty): New. (stderr_file_write): Rename to ... (stderr_file::write) ... this. Adjust. (stderr_file_fputs): Rename to ... (stderr_file::puts) ... this. Adjust. (stderr_fileopen, stdio_fileopen, gdb_fopen): Delete. (stderr_file::stderr_file): New. (tee_file_magic): Delete. (struct tee_file): Delete. (tee_file::tee_file): New. (tee_file_new): Delete. (tee_file::~tee_file): New. (tee_file_delete): Delete. (tee_file_flush): Rename to ... (tee_file::flush): ... this. Adjust. (tee_file_write): Rename to ... (tee_file::write): ... this. Adjust. (tee_file::write_async_safe): New. (tee_file_fputs): Rename to ... (tee_file::puts): ... this. Adjust. (tee_file_isatty): Rename to ... (tee_file::isatty): ... this. Adjust. * ui-file.h (struct obstack, struct ui_file): Don't forward-declare. (ui_file_new, ui_file_flush_ftype, set_ui_file_flush) (ui_file_write_ftype) (set_ui_file_write, ui_file_fputs_ftype, set_ui_file_fputs) (ui_file_write_async_safe_ftype, set_ui_file_write_async_safe) (ui_file_read_ftype, set_ui_file_read, ui_file_isatty_ftype) (set_ui_file_isatty, ui_file_rewind_ftype, set_ui_file_rewind) (ui_file_put_method_ftype, ui_file_put_ftype, set_ui_file_put) (ui_file_delete_ftype, set_ui_file_data, ui_file_fseek_ftype) (set_ui_file_fseek): Delete. (ui_file_data, ui_file_delete, ui_file_rewind) (struct ui_file): New. (ui_file_up): New. (class null_file): New. (null_stream): Declare. (ui_file_write_for_put, ui_file_put): Delete. (ui_file_xstrdup, ui_file_as_string, ui_file_obsavestring): Delete. (ui_file_fseek, mem_fileopen, stdio_fileopen, stderr_fileopen) (gdb_fopen, tee_file_new): Delete. (struct string_file): New. (struct stdio_file): New. (stdio_file_up): New. (struct stderr_file): New. (class tee_file): New. * ui-out.c (ui_out::field_stream): Take a 'string_file &' instead of a 'ui_file *'. Adjust. * ui-out.h (class ui_out) <field_stream>: Likewise. * utils.c (do_ui_file_delete, make_cleanup_ui_file_delete) (null_stream): Delete. (error_stream): Take a 'string_file &' instead of a 'ui_file *'. Adjust. * utils.h (struct ui_file): Delete forward declaration.. (make_cleanup_ui_file_delete, null_stream): Delete declarations. (error_stream): Take a 'string_file &' instead of a 'ui_file *'. * varobj.c (varobj_value_get_print_value): Use string_file. * xtensa-tdep.c (xtensa_verify_config): Use string_file. * gdbarch.c: Regenerate.
2017-01-23Minor simplification of (Python) find_thread_objectSimon Marchi1-8/+1
Since the reference to the Inferior Python object is managed by gdbpy_ref (RAII), we can return directly from the loop. It's just a leftover from the cleanups era. gdb/ChangeLog: * python/py-inferior.c (find_thread_object): Return directly from the loop. Remove "found" variable.
2017-01-20Fix Py_DECREF being executed without holding the GILSimon Marchi2-8/+8
When the gdbpy_ref objects get destroyed, they call Py_DECREF to decrement the reference counter of the python object they hold a reference to. Any time we call into the Python API, we should be holding the GIL. The gdbpy_enter object does that for us in an RAII-fashion. However, if gdbpy_enter is declared after a gdbpy_ref object in a function, gdbpy_enter's destructor will be called (and the GIL will be released) before gdbpy_ref's destructor is called. Therefore, we will end up calling Py_DECREF without holding the GIL. This became obvious with Python 3.6, where memory management functions have asserts to make sure that the GIL is held. This was exposed by tests py-as-string.exp, py-function.exp and py-xmethods. For example: (gdb) p $_as_string(enum_valid) Fatal Python error: Python memory allocator called without holding the GIL Current thread 0x00007f7f7b21c780 (most recent call first): [1] 18678 abort (core dumped) ./gdb -nx testsuite/outputs/gdb.python/py-as-string/py-as-string #0 0x00007ffff618bc37 in raise () from /lib/x86_64-linux-gnu/libc.so.6 #1 0x00007ffff618f028 in abort () from /lib/x86_64-linux-gnu/libc.so.6 #2 0x00007ffff6b104d6 in Py_FatalError (msg=msg@entry=0x7ffff6ba15b8 "Python memory allocator called without holding the GIL") at Python/pylifecycle.c:1457 #3 0x00007ffff6a37a68 in _PyMem_DebugCheckGIL () at Objects/obmalloc.c:1972 #4 0x00007ffff6a3804e in _PyMem_DebugFree (ctx=0x7ffff6e65290 <_PyMem_Debug+48>, ptr=0x24f8830) at Objects/obmalloc.c:1994 #5 0x00007ffff6a38e1d in PyMem_Free (ptr=<optimized out>) at Objects/obmalloc.c:442 #6 0x00007ffff6b866c6 in _PyFaulthandler_Fini () at ./Modules/faulthandler.c:1369 #7 0x00007ffff6b104bd in Py_FatalError (msg=msg@entry=0x7ffff6ba15b8 "Python memory allocator called without holding the GIL") at Python/pylifecycle.c:1431 #8 0x00007ffff6a37a68 in _PyMem_DebugCheckGIL () at Objects/obmalloc.c:1972 #9 0x00007ffff6a3804e in _PyMem_DebugFree (ctx=0x7ffff6e652c0 <_PyMem_Debug+96>, ptr=0x7ffff46b6040) at Objects/obmalloc.c:1994 #10 0x00007ffff6a38f55 in PyObject_Free (ptr=<optimized out>) at Objects/obmalloc.c:503 #11 0x00007ffff6a5f27e in unicode_dealloc (unicode=unicode@entry=0x7ffff46b6040) at Objects/unicodeobject.c:1794 #12 0x00007ffff6a352a9 in _Py_Dealloc (op=0x7ffff46b6040) at Objects/object.c:1786 #13 0x000000000063f28b in gdb_Py_DECREF (op=0x7ffff46b6040) at /home/emaisin/src/binutils-gdb/gdb/python/python-internal.h:192 #14 0x000000000063fa33 in gdbpy_ref_policy::decref (ptr=0x7ffff46b6040) at /home/emaisin/src/binutils-gdb/gdb/python/py-ref.h:35 #15 0x000000000063fa77 in gdb::ref_ptr<_object, gdbpy_ref_policy>::~ref_ptr (this=0x7fffffffcdf0, __in_chrg=<optimized out>) at /home/emaisin/src/binutils-gdb/gdb/common/gdb_ref_ptr.h:91 #16 0x000000000064d8b8 in fnpy_call (gdbarch=0x2b50010, language=0x115d2c0 <c_language_defn>, cookie=0x7ffff46b7468, argc=1, argv=0x7fffffffcf48) at /home/emaisin/src/binutils-gdb/gdb/python/py-function.c:145 The fix is to place the gdbpy_enter first in the function. I also cleaned up the comments a bit and removed the unnecessary initialization of the value variable. gdb/ChangeLog: * python/py-function.c (fnpy_call): Reorder declarations to have the gdbpy_enter object declared first. * python/py-xmethods.c (gdbpy_get_xmethod_arg_types): Likewise.
2017-01-20Fix python-interactive with Python 3.6Simon Marchi2-2/+10
New in v2: - Define PyMem_RawMalloc as PyMem_Malloc for Python < 3.4 and use PyMem_RawMalloc in the code. Since Python 3.4, the callback installed in PyOS_ReadlineFunctionPointer should return a value allocated with PyMem_RawMalloc instead of PyMem_Malloc. The reason is that PyMem_Malloc must be called with the Python Global Interpreter Lock (GIL) held, which is not the case in the context where this function is called. PyMem_RawMalloc was introduced for cases like this. In Python 3.6, it looks like they added an assert to verify that PyMem_Malloc was not called without the GIL. The consequence is that typing anything in the python-interactive mode of gdb crashes the process. The same behavior was observed with the official package on Arch Linux as well as with a manual Python build on Ubuntu 14.04. This is what is shown with a debug build of Python 3.6 (the error with a non-debug build is far less clear): (gdb) pi >>> print(1) Fatal Python error: Python memory allocator called without holding the GIL Current thread 0x00007f1459af8780 (most recent call first): [1] 21326 abort ./gdb and the backtrace: #0 0x00007ffff618bc37 in raise () from /lib/x86_64-linux-gnu/libc.so.6 #1 0x00007ffff618f028 in abort () from /lib/x86_64-linux-gnu/libc.so.6 #2 0x00007ffff6b104d6 in Py_FatalError (msg=msg@entry=0x7ffff6ba15b8 "Python memory allocator called without holding the GIL") at Python/pylifecycle.c:1457 #3 0x00007ffff6a37a68 in _PyMem_DebugCheckGIL () at Objects/obmalloc.c:1972 #4 0x00007ffff6a3804e in _PyMem_DebugFree (ctx=0x7ffff6e65290 <_PyMem_Debug+48>, ptr=0x24f8830) at Objects/obmalloc.c:1994 #5 0x00007ffff6a38e1d in PyMem_Free (ptr=<optimized out>) at Objects/obmalloc.c:442 #6 0x00007ffff6b866c6 in _PyFaulthandler_Fini () at ./Modules/faulthandler.c:1369 #7 0x00007ffff6b104bd in Py_FatalError (msg=msg@entry=0x7ffff6ba15b8 "Python memory allocator called without holding the GIL") at Python/pylifecycle.c:1431 #8 0x00007ffff6a37a68 in _PyMem_DebugCheckGIL () at Objects/obmalloc.c:1972 #9 0x00007ffff6a37aa3 in _PyMem_DebugMalloc (ctx=0x7ffff6e65290 <_PyMem_Debug+48>, nbytes=5) at Objects/obmalloc.c:1980 #10 0x00007ffff6a38d91 in PyMem_Malloc (size=<optimized out>) at Objects/obmalloc.c:418 #11 0x000000000064dbe2 in gdbpy_readline_wrapper (sys_stdin=0x7ffff6514640 <_IO_2_1_stdin_>, sys_stdout=0x7ffff6514400 <_IO_2_1_stdout_>, prompt=0x7ffff4d4f7d0 ">>> ") at /home/emaisin/src/binutils-gdb/gdb/python/py-gdb-readline.c:75 The documentation is very clear about it [1] and it was also mentioned in the "What's New In Python 3.4" page [2]. [1] https://docs.python.org/3/c-api/veryhigh.html#c.PyOS_ReadlineFunctionPointer [2] https://docs.python.org/3/whatsnew/3.4.html#changes-in-the-c-api gdb/ChangeLog: * python/python-internal.h (PyMem_RawMalloc): Define for Python < 3.4. * python/py-gdb-readline.c (gdbpy_readline_wrapper): Use PyMem_RawMalloc instead of PyMem_Malloc.
2017-01-10Add constructor and destructor to demangle_parse_infoTom Tromey1-5/+1
This adds a constructor and destructor to demangle_parse_info, and then changes all the users to use them. This removes make_cleanup_cp_demangled_name_parse_free and its single use. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-type.c (typy_legacy_template_argument): Update. * cp-support.h (struct demangle_parse_info) (demangle_parse_info, ~demangle_parse_info): Declare new members. (cp_demangled_name_to_comp): Return unique_ptr. (cp_demangled_name_parse_free) (make_cleanup_cp_demangled_name_parse_free) (cp_new_demangle_parse_info): Remove. * cp-support.c (do_demangled_name_parse_free_cleanup) (make_cleanup_cp_demangled_name_parse_free): Remove. (inspect_type, cp_canonicalize_string_full) (cp_canonicalize_string): Update. (mangled_name_to_comp): Change return type. (cp_class_name_from_physname, method_name_from_physname) (cp_func_name, cp_remove_params): Update. * cp-name-parser.y (demangle_parse_info): New constructor, from cp_new_demangle_parse_info. (~demangle_parse_info): New destructor, from cp_demangled_name_parse_free. (cp_merge_demangle_parse_infos): Update. (cp_demangled_name_to_comp): Change return type.
2017-01-10Remove cleanups from execute_gdb_commandTom Tromey1-6/+4
This replaces a cleanup in execute_gdb_command with an instance of std::string. Testing showed that this originally missed a cleanup that was returned by prevent_dont_repeat. This version of the patch changes prevent_dont_repeat to return a scoped_restore rather than a cleanup. 2017-01-10 Tom Tromey <tom@tromey.com> * top.c (prevent_dont_repeat): Change return type. * python/python.c (execute_gdb_command): Use std::string. Update. * guile/guile.c (gdbscm_execute_gdb_command): Update. * command.h (prevent_dont_repeat): Change return type. * breakpoint.c (bpstat_do_actions_1): Update.
2017-01-10Add scoped_value_markTom Tromey1-44/+18
This adds a scoped_value_mark class, that records the value mark in the constructor and then calls value_free_to_mark in the destructor. It then updates various spots in gdb to use this class, rather than a cleanup. It would be better overall to replace "struct value *" with a shared_ptr, maybe eliminating the need for this class (watchpoints would perhaps need some new mechanism as well). However, that's difficult to do. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-value.c (valpy_dereference, valpy_referenced_value) (valpy_reference_value, valpy_const_value, valpy_get_address) (valpy_get_dynamic_type, valpy_lazy_string, valpy_do_cast) (valpy_getitem, valpy_call, valpy_binop_throw, valpy_negative) (valpy_absolute, valpy_richcompare_throw): Use scoped_value_mark. * dwarf2loc.c (dwarf2_loc_desc_get_symbol_read_needs): Use scoped_value_mark. * dwarf2-frame.c (execute_stack_op): Use scoped_value_mark. * value.h (scoped_value_mark): New class.
2017-01-10Use class to manage BFD reference countsTom Tromey1-2/+2
This introduces a new specialization of gdb::ref_ptr that can be used to manage BFD reference counts. Then it changes most places in gdb to use this new class, rather than explicit reference-counting or cleanups. This patch removes make_cleanup_bfd_unref. If you look you will see a couple of spots using "release" where a use of gdb_bfd_ref_ptr would be cleaner. These will be fixed in the next patch. I think this patch fixes some latent bugs. For example, it seems to me that previously objfpy_add_separate_debug_file leaked a BFD. I'm not 100% certain that the macho_symfile_read_all_oso change is correct. The existing code here is hard for me to follow. One goal of this sort of automated reference counting, though, is to make it more difficult to make logic errors; so hopefully the code is clear now. 2017-01-10 Tom Tromey <tom@tromey.com> * windows-tdep.c (windows_xfer_shared_library): Update. * windows-nat.c (windows_make_so): Update. * utils.h (make_cleanup_bfd_unref): Remove. * utils.c (do_bfd_close_cleanup, make_cleanup_bfd_unref): Remove. * symfile.h (symfile_bfd_open) (find_separate_debug_file_in_section): Return gdb_bfd_ref_ptr. * symfile.c (read_symbols, symbol_file_add) (separate_debug_file_exists): Update. (symfile_bfd_open): Return gdb_bfd_ref_ptr. (generic_load, reread_symbols): Update. * symfile-mem.c (symbol_file_add_from_memory): Update. * spu-linux-nat.c (spu_bfd_open): Return gdb_bfd_ref_ptr. (spu_symbol_file_add_from_memory): Update. * solist.h (struct target_so_ops) <bfd_open>: Return gdb_bfd_ref_ptr. (solib_bfd_fopen, solib_bfd_open): Return gdb_bfd_ref_ptr. * solib.c (solib_bfd_fopen, solib_bfd_open): Return gdb_bfd_ref_ptr. (solib_map_sections, reload_shared_libraries_1): Update. * solib-svr4.c (enable_break): Update. * solib-spu.c (spu_bfd_fopen): Return gdb_bfd_ref_ptr. * solib-frv.c (enable_break2): Update. * solib-dsbt.c (enable_break): Update. * solib-darwin.c (gdb_bfd_mach_o_fat_extract): Return gdb_bfd_ref_ptr. (darwin_solib_get_all_image_info_addr_at_init): Update. (darwin_bfd_open): Return gdb_bfd_ref_ptr. * solib-aix.c (solib_aix_bfd_open): Return gdb_bfd_ref_ptr. * record-full.c (record_full_save): Update. * python/py-objfile.c (objfpy_add_separate_debug_file): Update. * procfs.c (insert_dbx_link_bpt_in_file): Update. * minidebug.c (find_separate_debug_file_in_section): Return gdb_bfd_ref_ptr. * machoread.c (macho_add_oso_symfile): Change abfd to gdb_bfd_ref_ptr. (macho_symfile_read_all_oso): Update. (macho_check_dsym): Return gdb_bfd_ref_ptr. (macho_symfile_read): Update. * jit.c (bfd_open_from_target_memory): Return gdb_bfd_ref_ptr. (jit_bfd_try_read_symtab): Update. * gdb_bfd.h (gdb_bfd_open, gdb_bfd_fopen, gdb_bfd_openr) (gdb_bfd_openw, gdb_bfd_openr_iovec) (gdb_bfd_openr_next_archived_file, gdb_bfd_fdopenr): Return gdb_bfd_ref_ptr. (gdb_bfd_ref_policy): New struct. (gdb_bfd_ref_ptr): New typedef. * gdb_bfd.c (gdb_bfd_open, gdb_bfd_fopen, gdb_bfd_openr) (gdb_bfd_openw, gdb_bfd_openr_iovec) (gdb_bfd_openr_next_archived_file, gdb_bfd_fdopenr): Return gdb_bfd_ref_ptr. * gcore.h (create_gcore_bfd): Return gdb_bfd_ref_ptr. * gcore.c (create_gcore_bfd): Return gdb_bfd_ref_ptr. (gcore_command): Update. * exec.c (exec_file_attach): Update. * elfread.c (elf_symfile_read): Update. * dwarf2read.c (dwarf2_get_dwz_file): Update. (try_open_dwop_file, open_dwo_file): Return gdb_bfd_ref_ptr. (open_and_init_dwo_file): Update. (open_dwp_file): Return gdb_bfd_ref_ptr. (open_and_init_dwp_file): Update. * corelow.c (core_open): Update. * compile/compile-object-load.c (compile_object_load): Update. * common/gdb_ref_ptr.h (ref_ptr::operator->): New operator. * coffread.c (coff_symfile_read): Update. * cli/cli-dump.c (bfd_openr_or_error, bfd_openw_or_error): Return gdb_bfd_ref_ptr. Rename. (dump_bfd_file, restore_command): Update. * build-id.h (build_id_to_debug_bfd): Return gdb_bfd_ref_ptr. * build-id.c (build_id_to_debug_bfd): Return gdb_bfd_ref_ptr. (find_separate_debug_file_by_buildid): Update.
2017-01-10Add gdb_ref_ptr.hTom Tromey1-126/+9
This adds a new gdb_ref_ptr.h, that implements a reference-counting smart pointer class, where the user of the class supplies a reference-counting policy object. This class will be used in the next patch, which changes most explicit BFD reference counts to use this new type. Meanwhile, this patch changes gdbpy_ref to be a specialization of this new class. This change required adding new nullptr_t overloads some operators in gdb_ref_ptr.h. I suspect this was needed because some Python header redefines NULL, but I'm not certain. 2017-01-10 Tom Tromey <tom@tromey.com> * common/gdb_ref_ptr.h: New file. * python/py-ref.h (struct gdbpy_ref_policy): New. (gdbpy_ref): Now a typedef.
2017-01-10Remove make_cleanup_py_decref and make_cleanup_py_xdecrefTom Tromey2-45/+0
make_cleanup_py_decref and make_cleanup_py_xdecref are now unused, so this patch removes themm. Future Python changes should use gdbpy_ref instead. 2017-01-10 Tom Tromey <tom@tromey.com> * python/python-internal.h (make_cleanup_py_decref) (make_cleanup_py_xdecref): Don't declare. * python/py-utils.c (py_decref, make_cleanup_py_decref) (py_xdecref, make_cleanup_py_xdecref): Remove.
2017-01-10Use gdbpy_ref rather than make_cleanup_py_decrefTom Tromey1-31/+28
This changes some spots in py-framefilter.c to use gdbpy_ref rather than make_cleanup_py_decref or make_cleanup_py_xdecref. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-framefilter.c (py_mi_print_variables): Use gdbpy_ref. (py_print_locals, enumerate_locals, py_print_args): Use gdbpy_ref.
2017-01-10Use gdbpy_ref in enumerate_argsTom Tromey1-35/+21
This changes enumerate_args to use gdbpy_ref, and gets rid of many gotos. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-framefilter.c (enumerate_args): Use gdbpy_ref.
2017-01-10Use gdbpy_ref in py-utils.cTom Tromey1-34/+15
This changes more places in py-utils.c to use gdbpy_ref. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-utils.c (unicode_to_encoded_string) (python_string_to_target_string) (python_string_to_target_python_string) (python_string_to_host_string, gdbpy_obj_to_string) (get_addr_from_python): Use gdbpy_ref.
2017-01-10Use gdbpy_ref in pyuw_object_attribute_to_pointerTom Tromey1-3/+2
This changes pyuw_object_attribute_to_pointer to use gdbpy_ref. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-unwind.c (pyuw_object_attribute_to_pointer): Use gdbpy_ref.
2017-01-10Use gdbpy_ref in python.cTom Tromey1-67/+53
This changes more places in python.c to use gdbpy_ref. Additionally, previously gdbpy_apply_type_printers would return EXT_LANG_RC_ERROR if a type printer returned None. However, that doesn't seem correct to me; this patch changes it to return EXT_LANG_RC_NOP in this case. 2017-01-10 Tom Tromey <tom@tromey.com> * python/python.c (eval_python_command, gdbpy_decode_line) (gdbpy_run_events, gdbpy_start_type_printers) (gdbpy_apply_type_printers): Use gdbpy_ref.
2017-01-10Use gdbpy_ref in py-param.cTom Tromey1-10/+8
This changes py-param.c to use gdbpy_ref in a couple more spots. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-param.c (get_doc_string, compute_enum_values): Use gdbpy_ref.
2017-01-10Use gdbpy_ref in py-inferior.cTom Tromey1-17/+6
This changes py-inferior.c to use gdbpy_ref in more places. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-inferior.c (find_thread_object, build_inferior_list): Use gdbpy_ref.
2017-01-10Use gdbpy_ref in py_print_frameTom Tromey1-10/+4
This changes py_print_frame to use gdbpy_ref in more places. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-framefilter.c (py_print_frame): Use gdbpy_ref.
2017-01-10Use gdbpy_ref in bpfinishpy_out_of_scopeTom Tromey1-4/+3
This changes bpfinishpy_out_of_scope to use gdbpy_ref. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-finishbreakpoint.c (bpfinishpy_out_of_scope): Use gdbpy_ref.
2017-01-10Use gdbpy_ref in py-cmd.cTom Tromey1-51/+30
This changes py-cmd.c to use gdbpy_ref in more places. This also fixes a latent memory leak in cmdpy_completer_helper, which unnecessarily increfs the result of PyObject_CallMethodObjArgs. This is not needed because that function returns a new reference. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-cmd.c (cmdpy_completer_helper): Use gdbpy_ref. Remove extra incref. (cmdpy_completer_handle_brkchars, cmdpy_completer, cmdpy_init): Use gdbpy_ref.
2017-01-10Use gdbpy_ref in gdbpy_breakpoint_cond_says_stopTom Tromey1-5/+3
This changes gdbpy_breakpoint_cond_says_stop to use gdbpy_ref rather than explicit reference management. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-breakpoint.c (gdbpy_breakpoint_cond_says_stop): Use gdbpy_ref.
2017-01-10Use gdbpy_ref in archpy_disassembleTom Tromey1-20/+9
This changes archpy_disassemble to use gdbpy_ref. It also fixes a latent bug where archpy_disassemble was decref'ing the results of a all to PyArg_ParseTupleAndKeywords. This is incorrect because PyArg_ParseTupleAndKeywords returns borrowed references. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-arch.c (archpy_disassemble): Use gdbpy_ref. Don't decref results of PyArg_ParseTupleAndKeywords.
2017-01-10Change python_run_simple_file to use gdbpy_refTom Tromey1-13/+5
This changes python_run_simple_file to use gdbpy_ref and unique_xmalloc_ptr. Thi fixes a latent bug in this function, where the error path previously ran the cleanups and then referred to one of the objects just freed. 2017-01-10 Tom Tromey <tom@tromey.com> * python/python.c (python_run_simple_file): Use unique_xmalloc_ptr, gdbpy_ref.
2017-01-10Use gdbpy_ref in py-prettyprint.cTom Tromey1-114/+92
This changes some spots in py-prettyprint.c to use gdbpy_ref. It also changes push_dummy_python_frame to be a class, rather than having it create a cleanup. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-prettyprint.c (print_stack_unless_memory_error) (print_string_repr, print_children): Use gdbpy_ref. (dummy_python_frame): New class. (dummy_python_frame::dummy_python_frame): Rename from push_dummy_python_frame. (py_restore_tstate): Remove.
2017-01-10Use gdbpy_ref in py_print_frameTom Tromey1-29/+12
This changes py_print_frame to use gdbpy_ref in a few spots. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-framefilter.c (py_print_frame): Use gdbpy_ref.
2017-01-10Remove ensure_python_envTom Tromey2-26/+0
All of gdb has been converted away from ensure_python_env and varobj_ensure_python_env now; so remove them. 2017-01-10 Tom Tromey <tom@tromey.com> * python/python.c (ensure_python_env, restore_python_env): Remove. * python/python-internal.h (ensure_python_env): Don't declare. * varobj.h (varobj_ensure_python_env): Don't declare. * varobj.c (varobj_ensure_python_env): Remove.
2017-01-10Change type of encoding argument to gdbpy_extract_lazy_stringTom Tromey3-12/+10
This changes gdbpy_extract_lazy_string's "encoding" argument to be a unique_xmalloc_ptr. I chose this rather than std::string because it can sometimes be NULL. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-prettyprint.c (print_string_repr, print_children): Update. * python/py-lazy-string.c (gdbpy_extract_lazy_string): Change type of "encoding". * varobj.c (varobj_value_get_print_value): Update. * python/python-internal.h (gdbpy_extract_lazy_string): Update.
2017-01-10Use gdbpy_enter in python.cTom Tromey1-45/+37
This changes the last functions in python.c to use gdbpy_enter. I split gdbpy_finish_initialization into two functions in order to avoid some "goto"s. 2017-01-10 Tom Tromey <tom@tromey.com> * python/python.c (python_command): Use gdbpy_enter, gdbpy_ref. (do_finish_initialization): New function. Use gdbpy_ref. (gdbpy_finish_initialization): Use gdbpy_enter. Call do_finish_initialization.
2017-01-10Use gdbpy_enter in py-param.cTom Tromey1-40/+35
This converts the remaining functions in py-param.c to use gdbpy_enter. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-param.c (get_set_value, get_show_value): Use gdbpy_enter, gdbpy_ref.
2017-01-10Use gdbpy_enter in fnpy_callTom Tromey1-21/+11
This changes fnpy_call to use gdbpy_enter and gdbpy_ref. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-function.c (fnpy_call): Use gdbpy_enter, gdbpy_ref.
2017-01-10Use gdbpy_enter in cmdpy_functionTom Tromey1-16/+10
This changes cmdpy_function to use gdbpy_enter and gdbpy_ref. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-cmd.c (cmdpy_function): Use gdbpy_enter, gdbpy_ref.
2017-01-10Use gdbpy_enter_varobj in py-varobj.cTom Tromey1-11/+5
This converts the remaining functions in py-varobj.c to use gdbpy_enter_varobj. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-varobj.c (py_varobj_iter_dtor, py_varobj_iter_next): Use gdbpy_enter_varobj.
2017-01-10Introduce gdbpy_enter_varobj and use itTom Tromey2-13/+19
This introduces gdbpy_enter_varobj, a subclass of gdbpy_enter; then changes one function in py-varobj.c to use it. gdbpy_enter_varobj takes a varobj as an argument, similar to varobj_ensure_python_env. 2017-01-10 Tom Tromey <tom@tromey.com> * varobj.c (gdbpy_enter_varobj): New constructor. * python/python-internal.h (gdbpy_enter_varobj): New class. * python/py-varobj.c (py_varobj_get_iterator): Use gdbpy_enter_varobj.
2017-01-10Use gdbpy_enter in py-xmethod.cTom Tromey1-91/+74
This changes the remaining functions in py-xmethod.c to use gdbpy_enter; using gdbpy_ref and unique_xmalloc_ptr as appropriate. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-xmethods.c (gdbpy_get_xmethod_result_type): Use gdbpy_enter, gdbpy_ref, unique_xmalloc_ptr. (gdbpy_invoke_xmethod): Use gdbpy_ref, gdbpy_enter. (gdbpy_get_xmethod_arg_types): Use gdbpy_ref, unique_xmalloc_ptr. (gdbpy_get_xmethod_arg_types): Use gdbpy_ref, gdbpy_enter.
2017-01-10Use gdbpy_ref in invoke_match_methodTom Tromey1-38/+12
Change invoke_match_method to use gdbpy_ref. I neglected to convert this function in my earlier series. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-xmethods.c (invoke_match_method): Use gdbpy_ref.
2017-01-10Use gdbpy_enter in gdbpy_get_matching_xmethod_workersTom Tromey1-95/+58
Change gdbpy_get_matching_xmethod_workers to use gdbpy_enter and gdbpy_ref. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-xmethods.c (gdbpy_get_matching_xmethod_workers): use gdbpy_enter, gdbpy_ref.
2017-01-10Use gdbpy_enter in python_interactive_commandTom Tromey1-1/+1
This changes python_interactive_command to use gdbpy_enter. Previously this function was leaving a dangling cleanup -- this is sort of ok in a command function, but IMO it's still better to clean up. 2017-01-10 Tom Tromey <tom@tromey.com> * python/python.c (python_interactive_command): Use gdbpy_enter.
2017-01-10Use gdbpy_enter in gdbpy_before_prompt_hookTom Tromey1-39/+33
Change gdbpy_before_prompt_hook to use gdbpy_enter and gdbpy_ref. This also rearranges the function a tiny bit to make it more clear. 2017-01-10 Tom Tromey <tom@tromey.com> * python/python.c (gdbpy_before_prompt_hook): Use gdbpy_enter, gdbpy_ref.
2017-01-10Use gdbpy_enter in py-prettyprint.cTom Tromey1-30/+15
Change py-prettyprint.c to use gdbpy_enter. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-prettyprint.c (gdbpy_apply_val_pretty_printer): Use gdbpy_enter, gdbpy_ref, unique_xmalloc_ptr.
2017-01-10Introduce htab_up and use gdbpy_enter in py-framefilter.cTom Tromey1-34/+21
This introduces a new "htab_up" typedef, which is a std::unique_ptr that can call htab_delete. Then it changes some code in py-framefilter.c to use both gdbpy_enter and the new htab_up. 2017-01-10 Tom Tromey <tom@tromey.com> * utils.h (htab_deleter): New struct. (htab_up): New typedef. * python/py-framefilter.c (gdbpy_apply_frame_filter): Use gdbpy_enter, gdbpy_ref, htab_up.
2017-01-10Use gdbpy_enter in py-unwind.cTom Tromey1-39/+33
Change py-unwind.c to use gdbpy_enter. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-unwind.c (pending_frame_invalidate): Remove. (pyuw_sniffer): Use gdbpy_enter and gdbpy_ref.