Commit Graph

36 Commits

Author SHA1 Message Date
Tom Tromey 3fabc0163a Do not include py-ref.h in most files
py-ref.h can really only be included from a specific spot in
python-internal.h.  The other includes are not useful, and cause
compilation errors if the includes are ever sorted.  So, remove these
includes.

Arguably, py-ref.h should simply not be a separate header.

gdb/ChangeLog
2019-01-22  Tom Tromey  <tom@tromey.com>

	* python/py-arch.c: Do not include py-ref.h.
	* python/py-bpevent.c: Do not include py-ref.h.
	* python/py-cmd.c: Do not include py-ref.h.
	* python/py-continueevent.c: Do not include py-ref.h.
	* python/py-event.h: Do not include py-ref.h.
	* python/py-evtregistry.c: Do not include py-ref.h.
	* python/py-finishbreakpoint.c: Do not include py-ref.h.
	* python/py-frame.c: Do not include py-ref.h.
	* python/py-framefilter.c: Do not include py-ref.h.
	* python/py-function.c: Do not include py-ref.h.
	* python/py-infevents.c: Do not include py-ref.h.
	* python/py-linetable.c: Do not include py-ref.h.
	* python/py-objfile.c: Do not include py-ref.h.
	* python/py-param.c: Do not include py-ref.h.
	* python/py-prettyprint.c: Do not include py-ref.h.
	* python/py-progspace.c: Do not include py-ref.h.
	* python/py-symbol.c: Do not include py-ref.h.
	* python/py-symtab.c: Do not include py-ref.h.
	* python/py-type.c: Do not include py-ref.h.
	* python/py-unwind.c: Do not include py-ref.h.
	* python/py-utils.c: Do not include py-ref.h.
	* python/py-value.c: Do not include py-ref.h.
	* python/py-varobj.c: Do not include py-ref.h.
	* python/py-xmethods.c: Do not include py-ref.h.
	* python/python.c: Do not include py-ref.h.
	* varobj.c: Do not include py-ref.h.
2019-01-22 20:35:21 -07:00
Tom Tromey 2a3c71d68d Remove more uses of explicit reference counting in Python
This changes some more place in the Python code to use gdbpy_ref
rather than explicit reference counting.  While doing this I found a
latent bug in typy_fields_items -- it was not checking for errors in
one spot.  I also changed valpy_dealloc to use Py_XDECREF rather than
an explicit "if".

gdb/ChangeLog
2019-01-03  Tom Tromey  <tom@tromey.com>

	* python/py-value.c (valpy_dealloc): Use Py_XDECREF.
	* python/py-type.c (typy_fields_items): Use gdbpy_ref.
	* python/py-progspace.c (pspy_set_printers): Use gdbpy_ref.
	(pspy_set_frame_filters, pspy_set_frame_unwinders)
	(pspy_set_type_printers): Likewise.
	* python/py-function.c (fnpy_init): Use gdbpy_ref.
	* python/py-cmd.c (cmdpy_init): Use gdbpy_ref.
	* python/py-objfile.c (objfpy_set_printers): Use gdbpy_ref.
	(objfpy_set_frame_filters, objfpy_set_frame_unwinders)
	(objfpy_set_type_printers): Likewise.
2019-01-03 14:49:18 -07:00
Joel Brobecker 42a4f53d2b Update copyright year range in all GDB files.
This commit applies all changes made after running the gdb/copyright.py
script.

Note that one file was flagged by the script, due to an invalid
copyright header
(gdb/unittests/basic_string_view/element_access/char/empty.cc).
As the file was copied from GCC's libstdc++-v3 testsuite, this commit
leaves this file untouched for the time being; a patch to fix the header
was sent to gcc-patches first.

gdb/ChangeLog:

	Update copyright year range in all GDB files.
2019-01-01 10:01:51 +04:00
Andrew Burgess b352ceb6b4 gdb/python: Make convert_values_to_python return gdbpy_ref<>
Make convert_values_to_python return a gdbpy_ref<> directly rather
than building a gdbpy_ref<>, releasing it, and then having a new
gdbpy_ref<> created to hold the result.

I also added a header comment to convert_values_to_python.

gdb/ChangeLog:

	* python/py-function.c (convert_values_to_python): Return
	gdbpy_ref<>. Add header comment.
	(fnpy_call): Adjust.
2018-10-25 12:20:18 +01:00
Tom Tromey 2b4ad2fe43 Consolidate gdb.GdbError handling
I noticed two nearly identical copies of the same code for handling
gdb.GdbError.  The only differences were in some error messages.
These differences didn't seem very important, so this patch pulls the
code out into a new function.

2018-09-23  Tom Tromey  <tom@tromey.com>

	* python/py-function.c (fnpy_call): Use gdbpy_handle_exception.
	* python/py-cmd.c (cmdpy_function): Use gdbpy_handle_exception.
	* python/python-internal.h (gdbpy_handle_exception): Declare.
	* python/py-utils.c (gdbpy_handle_exception): New function.
2018-09-23 23:15:12 -06:00
Joel Brobecker e2882c8578 Update copyright year range in all GDB files
gdb/ChangeLog:

        Update copyright year range in all GDB files
2018-01-02 07:38:06 +04:00
Tom Tromey 7780f18678 Turn gdbpy_ref into a template
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-10 12:24:31 -07:00
Simon Marchi b1ce65684d Fix Py_DECREF being executed without holding the GIL
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-20 21:06:51 -05:00
Tom Tromey 0e9dcc7587 Use gdbpy_enter in fnpy_call
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-10 19:13:53 -07:00
Tom Tromey 80bd970a4b Use gdbpy_ref in py-function.c
This changes some code in py-function.c to use gdbpy_ref.

2017-01-10  Tom Tromey  <tom@tromey.com>

	* python/py-function.c (convert_values_to_python, fnpy_init): Use
	gdbpy_ref.
2017-01-10 19:13:31 -07:00
Joel Brobecker 61baf725ec update copyright year range in GDB files
This applies the second part of GDB's End of Year Procedure, which
updates the copyright year range in all of GDB's files.

gdb/ChangeLog:

        Update copyright year range in all GDB files.
2017-01-01 10:52:34 +04:00
Tom Tromey 9b9720149d Use unique_xmalloc_ptr in Python code
This changes some utility functions in the Python code to return
unique_xmalloc_ptr, and then fixes up the callers.

I chose unique_xmalloc_ptr rather than std::string because at a few
call points the xmalloc'd string is released and ownership transferred
elsewhere.

This patch found a few existing memory leaks.  For example,
py-unwind.c called gdbpy_obj_to_string but never freed the result.

Built and regression tested on the buildbot.

2016-11-09  Tom Tromey  <tom@tromey.com>

	* varobj.h (varobj_get_display_hint): Change return type.
	* varobj.c (varobj_get_display_hint): Return unique_xmalloc_ptr.
	(varobj_value_get_print_value): Update.
	* python/python.c (gdbpy_before_prompt_hook, gdbpy_print_stack)
	(gdbpy_apply_type_printers): Update.
	* python/python-internal.h (unicode_to_target_string)
	(python_string_to_target_string, python_string_to_host_string)
	(gdbpy_obj_to_string, gdbpy_exception_to_string)
	(gdbpy_get_display_hint): Change return types.
	* python/py-varobj.c (py_varobj_iter_next): Update.
	* python/py-value.c (valpy_getitem, convert_value_from_python):
	Update.
	* python/py-utils.c (unicode_to_encoded_string)
	(unicode_to_target_string, python_string_to_target_string)
	(python_string_to_host_string, gdbpy_obj_to_string)
	(gdbpy_exception_to_string): Return unique_xmalloc_ptr.
	* python/py-unwind.c (pyuw_parse_register_id): Update.
	* python/py-type.c (typy_getitem): Update.
	* python/py-prettyprint.c (gdbpy_get_display_hint)
	(print_stack_unless_memory_error, print_children)
	(gdbpy_apply_val_pretty_printer): Update.
	* python/py-param.c (set_parameter_value): Update.
	(get_doc_string, call_doc_function): Return unique_xmalloc_ptr.
	(get_set_value, get_show_value, compute_enum_values, parmpy_init):
	Update.
	* python/py-infthread.c (thpy_set_name): Update.
	* python/py-function.c (fnpy_call, fnpy_init): Update.
	* python/py-framefilter.c (extract_sym): Change "name" to
	unique_xmalloc_ptr.
	(enumerate_args, enumerate_locals): Update.
	(py_print_frame): Use unique_xmalloc_ptr.
	* python/py-frame.c (frapy_read_var): Update.  Remove cleanup.
	* python/py-cmd.c (cmdpy_function, cmdpy_completer, cmdpy_init):
	Update.
	* python/py-breakpoint.c (bppy_set_condition): Use
	unique_xmalloc_ptr.
	(bppy_init): Likewise.  Remove cleanup.
	(local_setattro): Update.
	* mi/mi-cmd-var.c (print_varobj, mi_cmd_var_list_children)
	(varobj_update_one): Update.
2016-11-09 19:40:12 -07:00
Joel Brobecker 618f726fcb GDB copyright headers update after running GDB's copyright.py script.
gdb/ChangeLog:

        Update year range in copyright notice of all files.
2016-01-01 08:43:22 +04:00
Tom Tromey e36122e9d7 Fix redefinition errors in C++ mode
In C, we can forward declare static structure instances.  That doesn't
work in C++ though.  C++ treats these as definitions.  So then the
compiler complains about symbol redefinition, like:

 src/gdb/elfread.c:1569:29: error: redefinition of ‘const sym_fns elf_sym_fns_lazy_psyms’
 src/gdb/elfread.c:53:29: error: ‘const sym_fns elf_sym_fns_lazy_psyms’ previously declared here

The intent of static here is naturally to avoid making these objects
visible outside the compilation unit.  The equivalent in C++ would be
to instead define the objects in the anonymous namespace.  But given
that it's desirable to leave the codebase compiling as both C and C++
for a while, this just makes the objects extern.

(base_breakpoint_ops is already declared in breakpoint.h, so we can
just remove the forward declare from breakpoint.c)

gdb/ChangeLog:
2015-02-11  Tom Tromey  <tromey@redhat.com>
	    Pedro Alves <palves@redhat.com>

	* breakpoint.c (base_breakpoint_ops): Delete.
	* dwarf2loc.c (dwarf_expr_ctx_funcs): Make extern.
	* elfread.c (elf_sym_fns_gdb_index, elf_sym_fns_lazy_psyms): Make extern.
	* guile/guile.c (guile_extension_script_ops, guile_extension_ops): Make extern.
	* ppcnbsd-tdep.c (ppcnbsd2_sigtramp): Make extern.
	* python/py-arch.c (arch_object_type): Make extern.
	* python/py-block.c (block_syms_iterator_object_type): Make extern.
	* python/py-bpevent.c (breakpoint_event_object_type): Make extern.
	* python/py-cmd.c (cmdpy_object_type): Make extern.
	* python/py-continueevent.c (continue_event_object_type)
	* python/py-event.h (GDBPY_NEW_EVENT_TYPE): Remove 'qual'
	parameter.  Update all callers.
	* python/py-evtregistry.c (eventregistry_object_type): Make extern.
	* python/py-exitedevent.c (exited_event_object_type): Make extern.
	* python/py-finishbreakpoint.c (finish_breakpoint_object_type): Make extern.
	* python/py-function.c (fnpy_object_type): Make extern.
	* python/py-inferior.c (inferior_object_type, membuf_object_type): Make extern.
	* python/py-infevents.c (call_pre_event_object_type)
	(inferior_call_post_event_object_type).
	(memory_changed_event_object_type): Make extern.
	* python/py-infthread.c (thread_object_type): Make extern.
	* python/py-lazy-string.c (lazy_string_object_type): Make extern.
	* python/py-linetable.c (linetable_entry_object_type)
	(linetable_object_type, ltpy_iterator_object_type): Make extern.
	* python/py-newobjfileevent.c (new_objfile_event_object_type)
	(clear_objfiles_event_object_type): Make extern.
	* python/py-objfile.c (objfile_object_type): Make extern.
	* python/py-param.c (parmpy_object_type): Make extern.
	* python/py-progspace.c (pspace_object_type): Make extern.
	* python/py-signalevent.c (signal_event_object_type): Make extern.
	* python/py-symtab.c (symtab_object_type, sal_object_type): Make extern.
	* python/py-type.c (type_object_type, field_object_type)
	(type_iterator_object_type): Make extern.
	* python/python.c (python_extension_script_ops)
	(python_extension_ops): Make extern.
	* stap-probe.c (stap_probe_ops): Make extern.
2015-02-11 11:20:21 +00:00
Joel Brobecker 32d0add0a6 Update year range in copyright notice of all files owned by the GDB project.
gdb/ChangeLog:

        Update year range in copyright notice of all files.
2015-01-01 13:32:14 +04:00
Gary Benson c765fdb902 Remove spurious exceptions.h inclusions
defs.h includes utils.h, and utils.h includes exceptions.h.  All GDB
.c files include defs.h as their first line, so no file other than
utils.h needs to include exceptions.h.  This commit removes all such
inclusions.

gdb/ChangeLog:

	* ada-lang.c: Do not include exceptions.h.
	* ada-valprint.c: Likewise.
	* amd64-tdep.c: Likewise.
	* auto-load.c: Likewise.
	* block.c: Likewise.
	* break-catch-throw.c: Likewise.
	* breakpoint.c: Likewise.
	* btrace.c: Likewise.
	* c-lang.c: Likewise.
	* cli/cli-cmds.c: Likewise.
	* cli/cli-interp.c: Likewise.
	* cli/cli-script.c: Likewise.
	* completer.c: Likewise.
	* corefile.c: Likewise.
	* corelow.c: Likewise.
	* cp-abi.c: Likewise.
	* cp-support.c: Likewise.
	* cp-valprint.c: Likewise.
	* darwin-nat.c: Likewise.
	* dwarf2-frame-tailcall.c: Likewise.
	* dwarf2-frame.c: Likewise.
	* dwarf2loc.c: Likewise.
	* dwarf2read.c: Likewise.
	* eval.c: Likewise.
	* event-loop.c: Likewise.
	* event-top.c: Likewise.
	* f-valprint.c: Likewise.
	* frame-unwind.c: Likewise.
	* frame.c: Likewise.
	* gdbtypes.c: Likewise.
	* gnu-v2-abi.c: Likewise.
	* gnu-v3-abi.c: Likewise.
	* guile/scm-auto-load.c: Likewise.
	* guile/scm-breakpoint.c: Likewise.
	* guile/scm-cmd.c: Likewise.
	* guile/scm-frame.c: Likewise.
	* guile/scm-lazy-string.c: Likewise.
	* guile/scm-param.c: Likewise.
	* guile/scm-symbol.c: Likewise.
	* guile/scm-type.c: Likewise.
	* hppa-hpux-tdep.c: Likewise.
	* i386-tdep.c: Likewise.
	* inf-loop.c: Likewise.
	* infcall.c: Likewise.
	* infcmd.c: Likewise.
	* infrun.c: Likewise.
	* interps.c: Likewise.
	* interps.h: Likewise.
	* jit.c: Likewise.
	* linespec.c: Likewise.
	* linux-nat.c: Likewise.
	* linux-thread-db.c: Likewise.
	* m32r-rom.c: Likewise.
	* main.c: Likewise.
	* memory-map.c: Likewise.
	* mi/mi-cmd-break.c: Likewise.
	* mi/mi-cmd-stack.c: Likewise.
	* mi/mi-interp.c: Likewise.
	* mi/mi-main.c: Likewise.
	* monitor.c: Likewise.
	* nto-procfs.c: Likewise.
	* objc-lang.c: Likewise.
	* p-valprint.c: Likewise.
	* parse.c: Likewise.
	* ppc-linux-tdep.c: Likewise.
	* printcmd.c: Likewise.
	* probe.c: Likewise.
	* python/py-auto-load.c: Likewise.
	* python/py-breakpoint.c: Likewise.
	* python/py-cmd.c: Likewise.
	* python/py-finishbreakpoint.c: Likewise.
	* python/py-frame.c: Likewise.
	* python/py-framefilter.c: Likewise.
	* python/py-function.c: Likewise.
	* python/py-gdb-readline.c: Likewise.
	* python/py-inferior.c: Likewise.
	* python/py-infthread.c: Likewise.
	* python/py-lazy-string.c: Likewise.
	* python/py-linetable.c: Likewise.
	* python/py-param.c: Likewise.
	* python/py-prettyprint.c: Likewise.
	* python/py-symbol.c: Likewise.
	* python/py-type.c: Likewise.
	* python/py-value.c: Likewise.
	* python/python-internal.h: Likewise.
	* python/python.c: Likewise.
	* record-btrace.c: Likewise.
	* record-full.c: Likewise.
	* regcache.c: Likewise.
	* remote-fileio.c: Likewise.
	* remote-mips.c: Likewise.
	* remote.c: Likewise.
	* rs6000-aix-tdep.c: Likewise.
	* rs6000-nat.c: Likewise.
	* skip.c: Likewise.
	* solib-darwin.c: Likewise.
	* solib-dsbt.c: Likewise.
	* solib-frv.c: Likewise.
	* solib-ia64-hpux.c: Likewise.
	* solib-spu.c: Likewise.
	* solib-svr4.c: Likewise.
	* solib.c: Likewise.
	* spu-tdep.c: Likewise.
	* stack.c: Likewise.
	* stap-probe.c: Likewise.
	* symfile-mem.c: Likewise.
	* symmisc.c: Likewise.
	* target.c: Likewise.
	* thread.c: Likewise.
	* top.c: Likewise.
	* tracepoint.c: Likewise.
	* tui/tui-interp.c: Likewise.
	* typeprint.c: Likewise.
	* utils.c: Likewise.
	* valarith.c: Likewise.
	* valops.c: Likewise.
	* valprint.c: Likewise.
	* value.c: Likewise.
	* varobj.c: Likewise.
	* windows-nat.c: Likewise.
	* xml-support.c: Likewise.
2014-10-08 09:33:22 +01:00
Joel Brobecker ecd75fc8ee Update Copyright year range in all files maintained by GDB. 2014-01-01 07:54:24 +04:00
Doug Evans 256458bc0e Remove trailing whitespace.
Whitespace cleanup.
	* python/py-breakpoint.c: Remove trailing whitespace.
	* python/py-cmd.c: Ditto.
	* python/py-evts.c: Ditto.
	* python/py-finishbreakpoint.c: Ditto.
	* python/py-frame.c: Ditto.
	* python/py-function.c: Ditto.
	* python/py-inferior.c: Ditto.
	* python/py-infthread.c: Ditto.
	* python/py-param.c: Ditto.
	* python/py-prettyprint.c: Ditto.
	* python/py-symbol.c: Ditto.
	* python/py-type.c: Ditto.
	* python/py-utils.c: Ditto.
	* python/py-value.c: Ditto.
	* python/python-internal.h: Ditto.
	* python/python.c: Ditto.
2013-11-29 12:00:47 -08:00
Tom Tromey aa36459a92 * python/py-arch.c (gdbpy_initialize_arch): Use
gdb_pymodule_addobject.
	* python/py-block.c (gdbpy_initialize_blocks): Use
	gdb_pymodule_addobject.
	* python/py-breakpoint.c (gdbpy_initialize_breakpoints): Use
	gdb_pymodule_addobject.
	* python/py-cmd.c (gdbpy_initialize_breakpoints): Use
	gdb_pymodule_addobject.
	* python/py-event.c (gdbpy_initialize_event_generic): Use
	gdb_pymodule_addobject.
	* python/py-evtregistry.c (gdbpy_initialize_eventregistry): Use
	gdb_pymodule_addobject.
	* python/py-evts.c (add_new_registry): Use
	gdb_pymodule_addobject.
	(gdbpy_initialize_py_events): Likewise.
	* python/py-finishbreakpoint.c
	(gdbpy_initialize_finishbreakpoints): Use
	gdb_pymodule_addobject.
	* python/py-frame.c (gdbpy_initialize_frames): Use
	gdb_pymodule_addobject.
	* python/py-function.c (gdbpy_initialize_functions): Use
	gdb_pymodule_addobject.
	* python/py-inferior.c (gdbpy_initialize_inferior): Use
	gdb_pymodule_addobject.
	* python/py-infthread.c (gdbpy_initialize_thread): Use
	gdb_pymodule_addobject.
	* python/py-objfile.c (gdbpy_initialize_objfile): Use
	gdb_pymodule_addobject.
	* python/py-param.c (gdbpy_initialize_parameters): Use
	gdb_pymodule_addobject.
	* python/py-progspace.c (gdbpy_initialize_pspace): Use
	gdb_pymodule_addobject.
	* python/py-symbol.c (gdbpy_initialize_symbols): Use
	gdb_pymodule_addobject.
	* python/py-symtab.c (gdbpy_initialize_symtabs): Use
	gdb_pymodule_addobject.
	* python/py-type.c (gdbpy_initialize_types): Use
	gdb_pymodule_addobject.
	* python/py-utils.c (gdb_pymodule_addobject): New function.
	* python/py-value.c (gdbpy_initialize_values): Use
	gdb_pymodule_addobject.
	* python/python-internal.h (gdb_pymodule_addobject): Declare.
	* python/python.c (_initialize_python): Use
	gdb_pymodule_addobject.
2013-05-20 20:36:19 +00:00
Tom Tromey 999633ede7 * python/py-arch.c (gdbpy_initialize_arch): Return 'int'.
Check errors.
	* python/py-auto-load.c (gdbpy_initialize_auto_load): Return 'int'.
	* python/py-block.c (gdbpy_initialize_blocks): Return 'int'.
	Check errors.
	* python/py-breakpoint.c (gdbpy_initialize_breakpoints): Return 'int'.
	Check errors.
	* python/py-cmd.c (gdbpy_initialize_commands): Return 'int'.
	Check errors.
	* python/py-event.c (gdbpy_initialize_event): Return 'int'.
	Check errors.
	* python/py-event.h (GDBPY_NEW_EVENT_TYPE): Change generated
	init function to return 'int'.
	* python/py-evtregistry.c (gdbpy_initialize_eventregistry):
	Return 'int'.  Check errors.
	* python/py-evts.c (gdbpy_initialize_py_events): Return 'int'.
	Check errors.
	* python/py-finishbreakpoint.c (gdbpy_initialize_finishbreakpoints):
	Return 'int'.  Check errors.
	* python/py-frame.c (gdbpy_initialize_frames): Return 'int'.
	Check errors.
	* python/py-function.c (gdbpy_initialize_functions): Return 'int'.
	Check errors.
	* python/py-gdb-readline.c (gdbpy_initialize_gdb_readline):
	Check errors.
	* python/py-inferior.c (gdbpy_initialize_inferior): Return 'int'.
	Check errors.
	* python/py-infthread.c (gdbpy_initialize_thread): Return 'int'.
	Check errors.
	* python/py-lazy-string.c (gdbpy_initialize_lazy_string): Return 'int'.
	Check errors.
	* python/py-objfile.c (gdbpy_initialize_objfile): Return 'int'.
	Check errors.
	* python/py-param.c (gdbpy_initialize_parameters): Return 'int'.
	Check errors.
	* python/py-progspace.c (gdbpy_initialize_pspace): Return 'int'.
	Check errors.
	* python/py-symbol.c (gdbpy_initialize_symbols): Return 'int'.
	Check errors.
	* python/py-symtab.c (gdbpy_initialize_symtabs): Return 'int'.
	Check errors.
	* python/py-type.c (gdbpy_initialize_types): Return 'int'.
	Check errors.
	* python/py-value.c (gdbpy_initialize_values): Return 'int'.
	Check errors.
	* python/python-internal.h (gdbpy_initialize_auto_load,
	gdbpy_initialize_values, gdbpy_initialize_frames,
	gdbpy_initialize_symtabs, gdbpy_initialize_commands,
	gdbpy_initialize_symbols, gdbpy_initialize_symtabs,
	gdbpy_initialize_blocks, gdbpy_initialize_types,
	gdbpy_initialize_functions, gdbpy_initialize_pspace,
	gdbpy_initialize_objfile, gdbpy_initialize_breakpoints,
	gdbpy_initialize_finishbreakpoints,
	gdbpy_initialize_lazy_string, gdbpy_initialize_parameters,
	gdbpy_initialize_thread, gdbpy_initialize_inferior,
	gdbpy_initialize_eventregistry, gdbpy_initialize_event,
	gdbpy_initialize_py_events, gdbpy_initialize_stop_event,
	gdbpy_initialize_signal_event,
	gdbpy_initialize_breakpoint_event,
	gdbpy_initialize_continue_event,
	gdbpy_initialize_exited_event, gdbpy_initialize_thread_event,
	gdbpy_initialize_new_objfile_event, gdbpy_initialize_arch):
	Update.  Use CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION.
	* python/python.c (gdb_python_initialized): New global.
	(gdbpy_initialize_events): Return 'int'.  Check errors.
	(_initialize_python): Check errors.  Set
	gdb_python_initialized.
2013-05-20 20:28:52 +00:00
Tom Tromey 764123e402 * python/py-function.c (fnpy_init): Decref result of
PyObject_GetAttrString.
2013-05-20 20:12:04 +00:00
Tom Tromey 62eec1a534 * python/py-arch.c (arch_object_type): Use
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
	* python/py-block.c (block_syms_iterator_object_type):
	Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
	* python/py-bpevent.c (breakpoint_event_object_type):
	Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
	* python/py-cmd.c (cmdpy_object_type): Use
	CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
	* python/py-continueevent.c (continue_event_object_type):
	Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
	* python/py-event.h (GDBPY_NEW_EVENT_TYPE):
	Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
	* python/py-events.h (thread_event_object_type):
	Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
	* python/py-evtregistry.c (eventregistry_object_type): Use
	CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
	* python/py-exitedevent.c (exited_event_object_type):
	Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
	* python/py-finishbreakpoint.c (finish_breakpoint_object_type):
	Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
	* python/py-function.c (fnpy_object_type): Use
	CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
	* python/py-inferior.c (inferior_object_type, membuf_object_type):
	Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
	* python/py-infthread.c (thread_object_type): Use
	CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
	* python/py-lazy-string.c (lazy_string_object_type):
	Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
	* python/py-newobjfileevent.c (new_objfile_event_object_type):
	Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
	* python/py-objfile.c (objfile_object_type): Use
	CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
	* python/py-param.c (parmpy_object_type):
	Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
	* python/py-progspace.c (pspace_object_type):
	Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
	* python/py-signalevent.c (signal_event_object_type):
	Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
	* python/py-symtab.c (symtab_object_type, sal_object_type): Use
	CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
	* python/py-type.c (type_object_type, field_object_type)
	(type_iterator_object_type): Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
	* python/py-internal.h (CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF): New
	define.
	(value_object_type, block_object_type, symbol_object_type)
	(event_object_type, stop_event_object_type, breakpoint_object_type)
	(frame_object_type): Use CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF.
2013-05-20 20:09:01 +00:00
Joel Brobecker 28e7fd6234 Update years in copyright notice for the GDB files.
Two modifications:
  1. The addition of 2013 to the copyright year range for every file;
  2. The use of a single year range, instead of potentially multiple
     year ranges, as approved by the FSF.
2013-01-01 06:33:28 +00:00
Paul Koning 9a27f2c60d Add support for Python 3.
* NEWS: Mention Python 3 support.
* varobj.c (value_get_print_value): Use
python_string_to_target_string.
* python/py-block.c: Use PyVarObject_HEAD_INIT in initialization
of type objects.
* python/py-breakpoint.c: Ditto.
* python/py-cmd.c:  Ditto.
* python/py-event.c: Ditto.
* python/py-event.h: Ditto.
* python/py-evtregistry.c: Ditto.
* python/py-finishbreakpoint.c: Ditto.
* python/py-frame.c: Ditto.
* python/py-function.c: Ditto.
* python/py-infthread.c: Ditto.
* python/py-lazy-string.c: Ditto.
* python/py-progspace.c: Ditto.
* /python/py-symbol.c: Ditto.
* python/py-evts.c:  (gdbpy_initialize_py_events): Add module
initialization for Python 3.
* python/py-inferior.c: Use PyVarObject_HEAD_INIT in initialization
of type objects.
(infpy_read_memory): Return memoryview object if Python 3.
(infpy_write_memory): Use "s*" operand parsing code for Python 3.
(infpy_search_memory): Ditto.
(get_buffer): New function for Python 3.
* python/py-objfile.c: Use PyVarObject_HEAD_INIT in initialization
of type objects.
(objfpy_dealloc): Use Py_TYPE to call tp_free.
* python/py-param.c: Use PyVarObject_HEAD_INIT in initialization
of type objects.
(get_attr): Use PyUnicode_CompareWithASCIIString if Python 3.
(set_attr): Ditto.
* python/py-prettyprint.c (print_string_repr): use PyBytes methods
instead of PyString methods if Python 3.
(print_children): Skip push_dummy_python_frame call if Python 3.
* python/py-symtab.c: Use PyVarObject_HEAD_INIT in initialization
of type objects.
(salpy_dealloc): Use Py_TYPE to call tp_free.
* python/py-type.c: Use PyVarObject_HEAD_INIT in initialization
of type objects.
(field_dealloc): Use Py_TYPE to call tp_free.
(typy_dealloc): Ditto.
(type_object_as_number): Adjust struct initializations for
differences in layout for Python 2 vs. Python 3.
* python/py-utils.c (python_string_to_unicode): Omit non-Unicode
string case for Python 3.
(unicode_to_encoded_python_string): Shorten code (no functional
change).
(python_string_to_target_python_string): Comment that in Python 3
returned value is a Python "bytes" type.
(gdbpy_is_string): Omit non-Unicode string check in Python 3.
(gdb_py_object_from_longest): Omit non-long integer case in Python
3.
(gdb_py_object_from_ulongest): Ditto.
* python/py-value.c: Use PyVarObject_HEAD_INIT in initialization
of type objects.
(valpy_dealloc): Use Py_TYPE to call tp_free.
(valpy_int): Omit function if Python 3.
(convert_value_from_python): Use "%S" format (Python object as a
string) if Python 3.
(value_object_as_number): Adjust struct initializations for
differences in layout for Python 2 vs. Python 3.
* python/python-config.py: Adjust syntax for Python 3
compatibility.
Include "sys.abiflags" string as part of python library name, if
that attribute exists (Python 3).
* python/python-internal.h (IS_PY3): Define if Python 3.
(Py_TPFLAGS_HAVE_ITER, Py_TPFLAGS_CHECKTYPES): Define with
placeholder value if Python 3.
(PyInt_Check, PyInt_FromLong, PyInt_AsLong, PyString_FromString,
PyString_Decode, PyString_FromFormat, PyString_Check): Define as
analogous Python 3 API function if Python 3.
(PyVarObject_HEAD_INIT): Define if not already defined.
(Py_TYPE): Ditto.
* python/python.c (eval_python_command): Omit Py_FlushLine call if
Python 3.
Check return values of all Python API calls for error.
Supply dummy "python" and "python-interactive" commands if Python
initialization failed.
(_initialize_python): Convert argc to wchar_t** if Python 3.
Add module initialization for Python 3.
(finish_python_initialization): Pass wchar_t * argument to
PySys_SetPath if Python 3.
* python/lib/gdb/__init__.py: Define "reload" if Python 3.
(_GdbFile): New class for common output file behavior.
(GdbOutFile): Subclass from _GdbFile.
(GdbOutputErrorFile): Ditto.
(auto_load_packages): Adjust syntax for Python 3 compatibility.
* python/lib/gdb/printing.py: Define basestr and int if Python 3.
* python/lib/gdb/prompt.py: Use sorted() function rather than
sort() method.
* python/lib/gdb/command/explore.py: Define raw_input if Python 3.
Adjust syntax for Python 3 compatibility.
* python/lib/gdb/command/pretty_printers.py: Use sorted() function
rather than sort() method.
Adjust syntax for Python 3 compatibility.
* python/lib/gdb/command/type_printers.py: Ditto.
* doc/gdb.texinfo (Inferior.read_memory): Mention that the return
value is a memoryview object if Python 3.
2012-12-12 16:47:30 +00:00
Joel Brobecker 0b30217134 Copyright year update in most files of the GDB Project.
gdb/ChangeLog:

        Copyright year update in most files of the GDB Project.
2012-01-04 08:17:56 +00:00
Phil Muldoon f77b9a5df0 2011-10-27 Phil Muldoon <pmuldoon@redhat.com>
PR python/13331

	* python/py-function.c (fnpy_call): Check 'args' is not NULL.
	(convert_values_to_python): Return on Python tuple allocation
	failure.  Return NULL on value conversion error.
2011-10-27 10:29:58 +00:00
Eli Zaretskii 6a1b16642b * python/py-breakpoint.c (gdbpy_initialize_breakpoints): Move the
initialization of the tp_new member to the corresponding
 gdbpy_initialize_* function.
 * python/py-cmd.c (gdbpy_initialize_commands): Likewise.
 * python/py-frame.c (gdbpy_initialize_frames): Likewise.
 * python/py-function.c (gdbpy_initialize_functions): Likewise.
 * python/py-inferior.c (gdbpy_initialize_inferior): Likewise.
 * python/py-param.c (gdbpy_initialize_parameters): Likewise.
2011-08-05 14:24:10 +00:00
Tom Tromey ddd49eeec4 * varobj.c (update_dynamic_varobj_children): Make 'name' const.
* symtab.h (lookup_struct, lookup_union, lookup_enum): Update.
	* python/python.c (gdbpy_parameter): Make 'arg' const.
	(execute_gdb_command): Likewise.
	(gdbpy_decode_line): Likewise.  Copy it.
	(gdbpy_parse_and_eval): Make 'expr_string' const.  Copy it.
	(gdbpy_write): Make 'arg' const.
	* python/py-type.c (typy_lookup_typename): Make 'type_name'
	const.
	(gdbpy_lookup_type): Likewise.
	* python/py-prettyprint.c (print_children): Make 'name' const.
	* python/py-param.c (parmpy_init): Make 'name' const.  Copy it.
	* python/py-inferior.c (infpy_write_memory): Make 'buf_len' a
	Py_ssize_t.
	* python/py-function.c (fnpy_init): Make 'name' const.
	* python/py-cmd.c (cmdpy_init): Make 'name' const.  Copy it.
	(gdbpy_string_to_argv): Make 'input' const.
	* python/py-breakpoint.c (bppy_init): Make 'spec' const.  Copy
	it.
	* gdbtypes.h (lookup_typename): Update.
	* gdbtypes.c (lookup_typename): Make 'name' const.
	(lookup_struct): Likewise.
	(lookup_union): Likewise.
	(lookup_enum): Likewise.
2011-06-24 19:47:37 +00:00
Phil Muldoon 057758407c 2011-03-21 Phil Muldoon <pmuldoon@redhat.com>
PR python/12183

	* python/py-function.c (fnpy_call): Treat GdbErrors differently to
	other error classes.  Do not print stack trace.

2011-03-21  Phil Muldoon  <pmuldoon@redhat.com>

        PR python/12183

	* gdb.python/py-function.exp: Add GdbError tests.
2011-03-22 09:38:16 +00:00
Joel Brobecker 7b6bb8daac run copyright.sh for 2011. 2011-01-01 15:34:07 +00:00
Jan Kratochvil 8dc785338e gdb/
* python/py-breakpoint.c (bppy_set_condition): New comment.
	* python/py-cmd.c (cmdpy_function): Call also gdbpy_print_stack for
	failed PyUnicode_Decode.
	(cmdpy_completer): Skip element for failed
	python_string_to_host_string.
	(cmdpy_init): Return -1 on failed python_string_to_host_string.
	* python/py-frame.c (frapy_read_var): Extend the function comment.
	* python/py-function.c (fnpy_init): Return -1 on failed
	python_string_to_host_string.
	* python/py-inferior.c (infpy_read_memory, infpy_write_memory): Extend
	the function comment.
	(infpy_search_memory): Extend the function comment.  Remove the
	PyErr_SetString call on already set error state.
	* python/py-param.c (set_parameter_value): Extend the function
	comment.  Return -1 on failed python_string_to_host_string, twice.
	(set_attr): Extend the function comment.
	(compute_enum_values): Extend the function comment.  New variable
	back_to.  Protect self->enumeration by BACK_TO cleanups.  Return 0 on
	failed python_string_to_host_string.
	(get_doc_string): Call gdbpy_print_stack on failed
	python_string_to_host_string.
	(parmpy_init): Extend the function comment.
	* python/py-prettyprint.c (pretty_print_one_value): Likewise.
	(gdbpy_get_display_hint, print_children): Call gdbpy_print_stack on
	failed python_string_to_host_string.
	* python/py-value.c (valpy_new, valpy_getitem, valpy_call)
	(valpy_binop, valpy_richcompare): Extend the function comment.
	* python/python.c
	(struct python_env) <error_type, error_value, error_traceback>: New
	fields.
	(restore_python_env): Handle PyErr_Occurred.  Call PyErr_Restore.
	(ensure_python_env): Call PyErr_Fetch.
	* varobj.c (update_dynamic_varobj_children): Call gdbpy_print_stack on
	failed convert_value_from_python.
	(value_get_print_value): Call gdbpy_print_stack on failed
	python_string_to_target_python_string.

gdb/testsuite/
	* gdb.python/py-error.exp: New file.
	* gdb.python/py-error.py: New file.
2010-10-13 13:24:40 +00:00
Michael Snyder d59b6f6c38 2010-05-17 Michael Snyder <msnyder@vmware.com>
* python/py-auto-load.c: White space.
	* python/py-block.c: White space.
	* python/py-breakpoint.c: White space.
	* python/py-cmd.c: White space.
	* python/py-function.c: White space.
	* python/py-lazy-string.c: White space.
	* python/py-objfile.c: White space.
	* python/py-param.c: White space.
	* python/py-prettyprint.c: White space.
	* python/py-progspace.c: White space.
	* python/py-symtab.c: White space.
	* python/python.c: White space.
	* python/py-type.c: White space.
	* python/py-utils.c: White space.
	* python/py-value.c: White space.
2010-05-17 21:23:25 +00:00
Michael Snyder f92adf3ccc 2010-05-07 Michael Snyder <msnyder@vmware.com>
* python/python.c (execute_gdb_command): Remove unused variables.
	* python/py-block.c (gdbpy_block_for_pc): Remove unused variable.
	* python/py-breakpoint.c (gdbpy_breakpoint_created):
	Remove unused variable.
	* python/py-cmd.c (cmdpy_function): Remove unused variable.
	(cmdpy_completer): Remove unused variable.
	* python/py-frame.c (frapy_find_sal): Remove unused variable.
	* python/py-function.c (fnpy_call): Remove unused variable.
	* python/py-objfile.c (objfile_to_objfile_object):
	Remove unused variable.
	* python/py-param.c (parmpy_init): Remove unused variable.
	* python/py-prettyprint.c (apply_varobj_pretty_printer):
	Remove unused variable.
	(gdbpy_default_visualizer): Remove unused variable.
	* python/py-progspace.c (pspace_to_pspace_object):
	Remove unused variable.
	* python/py-symtab.c (symtab_and_line_to_sal_object):
	Remove unused variable.
	* python/py-type.c (typy_template_argument):
	Remove unused variable.
	* python/py-value.c (valpy_string): Remove unused variable.
	(convert_value_from_python): Remove unused variables.
2010-05-07 19:26:30 +00:00
Joel Brobecker 4c38e0a4fc Update copyright year in most headers.
Automatic update by copyright.sh.
2010-01-01 07:32:07 +00:00
Tom Tromey ce0420dced 2009-09-21 Jason Orendorff <jason.orendorff@gmail.com>
PR python/10666:
	* python/py-function.c (fnpy_init): Use xstrdup.
2009-09-21 16:18:42 +00:00
Joel Brobecker 5172aecbd2 Checking in this patch for Thiago: Rename python-* files into py-*,
more 8+3 friendly.


gdb/
        * Makefile.in (py-cmd.o): Renamed from python-cmd.o.  Updated
        references.
        (py-frame.o): Renamed from python-frame.o.  Updated references.
        (py-function.o): Renamed from python-function.o.  Updated references.
        (py-objfile.o): Renamed from python-objfile.o.  Updated references.
        (py-prettyprint.o): Renamed from python-prettyprint.o.  Updated
+references.
        (py-type.o): Renamed from python-type.o.  Updated references.
        (py-utils.o): Renamed from python-utils.o.  Updated references.
        (py-value.o): Renamed from python-value.o.  Updated references.
        * py-cmd.o: Renamed from python-cmd.o.
        * py-frame.o: Renamed from python-frame.o.
        * py-function.o: Renamed from python-function.o.
        * py-objfile.o: Renamed from python-objfile.o.
        * py-prettyprint.o: Renamed from python-prettyprint.o.
        * py-type.o: Renamed from python-type.o.
        * py-utils.o: Renamed from python-utils.o.
        * py-value.o: Renamed from python-value.o.

gdb/testsuite/
        * gdb.python/Makefile.in (EXECUTABLES): Adjust to new executable
        names, add missing ones.
        * gdb.python/py-cmd.exp: Rename from python-cmd.exp.
        * gdb.python/py-frame.c: Rename from python-frame.c.
        * gdb.python/py-frame.exp: Rename from python-frame.exp.  Adjust
        testfile name.
        * gdb.python/py-function.exp: Rename from python-function.exp.
        * gdb.python/py-mi.exp: Rename from python-mi.exp.  Adjust
        testfile name.
        * gdb.python/py-prettyprint.c: Rename from python-prettyprint.c.
        * gdb.python/py-prettyprint.exp: Rename from python-prettyprint.exp.
        Adjust testfile name.
        * gdb.python/py-prettyprint.py: Rename from python-prettyprint.py.
        * gdb.python/py-template.cc: Rename from python-template.cc.
        * gdb.python/py-template.exp: Rename from python-template.exp.
        Adjust testfile name.
        * gdb.python/py-value.c: Rename from python-value.c.
        * gdb.python/py-value.exp: Rename from python-value.exp.  Adjust
        testfile name.
2009-09-09 17:45:42 +00:00