binutils-gdb/gdb/python
Simon Marchi 1256af7d1a python: Provide textual representation for Inferior and Objfile
Printing a GDB Python object is notoriously not helpful:

>>> print(gdb.selected_inferior())
<gdb.Inferior object at 0x7fea59aed198>
>>> print(gdb.objfiles())
[<gdb.Objfile object at 0x7fea59b57c90>]

This makes printing debug traces more difficult than it should be.  This
patch provides some repr() implementation for these two types (more to
come if people agree with the idea, but I want to test the water first).
Here's the same example as above, but with this patch:

>>> print(gdb.selected_inferior())
<gdb.Inferior num=1>
>>> print(gdb.objfiles())
[<gdb.Objfile filename=/home/emaisin/build/binutils-gdb-gcc-git/gdb/test>]

I implemented repr rather than str, because when printing a list (or
another container I suppose), Python calls the repr method of the
elements.  This is useful when printing a list of inferiors or objfiles.
The print(gdb.objfiles()) above would not have worked if I had
implemented str.

I found this post useful to understand the difference between repr and
str:

  https://stackoverflow.com/questions/1436703/difference-between-str-and-repr

gdb/ChangeLog:

	* python/py-inferior.c (infpy_repr): New.
	(inferior_object_type): Register infpy_repr.
	* python/py-objfile.c (objfpy_repr): New.
	(objfile_object_type): Register objfpy_repr.

gdb/testsuite/ChangeLog:

	* gdb.python/py-inferior.exp: Test repr() of gdb.Inferior.
	* gdb.python/py-objfile.exp: Test repr() of gdb.Objfile.
	* gdb.python/py-symtab.exp: Update test printing an objfile.

gdb/doc/ChangeLog:

	* python.texi (Basic Python): Mention the string representation
	of GDB Python objects.
2018-09-13 11:54:38 -04:00
..
lib/gdb
py-all-events.def
py-arch.c
py-auto-load.c
py-block.c
py-bpevent.c gdb/python: Use copy-initialization more when possible 2018-08-24 22:57:16 +01:00
py-breakpoint.c Simple unused variable removals 2018-07-22 13:20:01 -06:00
py-cmd.c Change Python code to use new_reference 2018-04-30 11:33:12 -06:00
py-continueevent.c gdb/python: Use copy-initialization more when possible 2018-08-24 22:57:16 +01:00
py-event-types.def
py-event.c
py-event.h Fix 8.2 regression in gdb.python/py-evthreads.exp w/ gdbserver (PR gdb/23379) 2018-08-24 22:13:30 +01:00
py-events.h
py-evtregistry.c
py-evts.c
py-exitedevent.c gdb/python: Use copy-initialization more when possible 2018-08-24 22:57:16 +01:00
py-finishbreakpoint.c Use thread_info and inferior pointers more throughout 2018-06-21 17:09:31 +01:00
py-frame.c
py-framefilter.c MI: Fix printing of frame architecture with Python frame filters enabled 2018-08-27 17:12:41 -04:00
py-function.c
py-gdb-readline.c Remove "repeat" argument from command_line_input 2018-08-17 16:39:06 -06:00
py-inferior.c python: Provide textual representation for Inferior and Objfile 2018-09-13 11:54:38 -04:00
py-infevents.c gdb/python: Use copy-initialization more when possible 2018-08-24 22:57:16 +01:00
py-infthread.c Remove ptid_get_tid 2018-07-03 11:36:44 -06:00
py-instruction.c
py-instruction.h
py-lazy-string.c
py-linetable.c
py-newobjfileevent.c gdb/python: Use copy-initialization more when possible 2018-08-24 22:57:16 +01:00
py-objfile.c python: Provide textual representation for Inferior and Objfile 2018-09-13 11:54:38 -04:00
py-param.c Fix a memory leak in py-param.c 2018-06-20 21:10:10 -06:00
py-prettyprint.c python: Make two functions return gdbpy_ref<> 2018-09-09 08:13:17 +01:00
py-progspace.c
py-record-btrace.c Use thread_info and inferior pointers more throughout 2018-06-21 17:09:31 +01:00
py-record-btrace.h
py-record-full.c
py-record-full.h
py-record.c Use thread_info and inferior pointers more throughout 2018-06-21 17:09:31 +01:00
py-record.h Use thread_info and inferior pointers more throughout 2018-06-21 17:09:31 +01:00
py-ref.h
py-signalevent.c gdb/python: Use copy-initialization more when possible 2018-08-24 22:57:16 +01:00
py-stopevent.c Fix 8.2 regression in gdb.python/py-evthreads.exp w/ gdbserver (PR gdb/23379) 2018-08-24 22:13:30 +01:00
py-stopevent.h
py-symbol.c
py-symtab.c
py-threadevent.c Initialize variable in py_get_event_thread 2018-08-25 11:52:24 -04:00
py-type.c Remove a static buffer from cp-name-parser.y 2018-06-01 10:46:47 -06:00
py-unwind.c Simple unused variable removals 2018-07-22 13:20:01 -06:00
py-utils.c
py-value.c Use unique_xmalloc_ptr for read_string 2018-06-18 12:51:02 -06:00
py-varobj.c
py-xmethods.c
python-config.py configure uses incorrect link order when testing libpython 2018-05-04 10:08:09 -04:00
python-internal.h python: Make two functions return gdbpy_ref<> 2018-09-09 08:13:17 +01:00
python.c Fix help text for "python" command 2018-09-10 07:44:24 -06:00
python.h