mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2025-01-18 12:24:38 +08:00
2988a36005
The documentation suggests that we implement gdb.Value.__init__, however, this is not currently true, we really implement gdb.Value.__new__. This will cause confusion if a user tries to sub-class gdb.Value. They might write: class MyVal (gdb.Value): def __init__ (self, val): gdb.Value.__init__(self, val) obj = MyVal(123) print ("Got: %s" % obj) But, when they source this code they'll see: (gdb) source ~/tmp/value-test.py Traceback (most recent call last): File "/home/andrew/tmp/value-test.py", line 7, in <module> obj = MyVal(123) File "/home/andrew/tmp/value-test.py", line 5, in __init__ gdb.Value.__init__(self, val) TypeError: object.__init__() takes exactly one argument (the instance to initialize) (gdb) The reason for this is that, as we don't implement __init__ for gdb.Value, Python ends up calling object.__init__ instead, which doesn't expect any arguments. The Python docs suggest that the reason why we might take this approach is because we want gdb.Value to be immutable: https://docs.python.org/3/c-api/typeobj.html#c.PyTypeObject.tp_new But I don't see any reason why we should require gdb.Value to be immutable when other types defined in GDB are not. This current immutability can be seen in this code: obj = gdb.Value(1234) print("Got: %s" % obj) obj.__init__ (5678) print("Got: %s" % obj) Which currently runs without error, but prints: Got: 1234 Got: 1234 In this commit I propose that we switch to using __init__ to initialize gdb.Value objects. This does introduce some additional complexity, during the __init__ call a gdb.Value might already be associated with a gdb value object, in which case we need to cleanly break that association before installing the new gdb value object. However, the cost of doing this is not great, and the benefit - being able to easily sub-class gdb.Value seems worth it. After this commit the first example above works without error, while the second example now prints: Got: 1234 Got: 5678 In order to make it easier to override the gdb.Value.__init__ method, I have tweaked the definition of gdb.Value.__init__. The second, optional argument to __init__ is a gdb.Type, if this argument is not present then GDB figures out a suitable type. However, if we want to override the __init__ method in a sub-class, and still support the default argument, it is easier to write: class MyVal (gdb.Value): def __init__ (self, val, type=None): gdb.Value.__init__(self, val, type) Currently, passing None for the Type will result in an error: TypeError: type argument must be a gdb.Type. After this commit I now allow the type argument to be None, in which case GDB figures out a suitable type just as if the type had not been passed at all. Unless a user is trying to reinitialize a value, or create sub-classes of gdb.Value, there should be no user visible changes after this commit. |
||
---|---|---|
bfd | ||
binutils | ||
config | ||
contrib | ||
cpu | ||
elfcpp | ||
etc | ||
gas | ||
gdb | ||
gdbserver | ||
gdbsupport | ||
gnulib | ||
gold | ||
gprof | ||
include | ||
intl | ||
ld | ||
libbacktrace | ||
libctf | ||
libdecnumber | ||
libiberty | ||
opcodes | ||
readline | ||
sim | ||
texinfo | ||
zlib | ||
.cvsignore | ||
.gitattributes | ||
.gitignore | ||
ar-lib | ||
ChangeLog | ||
compile | ||
config-ml.in | ||
config.guess | ||
config.rpath | ||
config.sub | ||
configure | ||
configure.ac | ||
COPYING | ||
COPYING3 | ||
COPYING3.LIB | ||
COPYING.LIB | ||
COPYING.LIBGLOSS | ||
COPYING.NEWLIB | ||
depcomp | ||
djunpack.bat | ||
install-sh | ||
libtool.m4 | ||
lt~obsolete.m4 | ||
ltgcc.m4 | ||
ltmain.sh | ||
ltoptions.m4 | ||
ltsugar.m4 | ||
ltversion.m4 | ||
MAINTAINERS | ||
Makefile.def | ||
Makefile.in | ||
Makefile.tpl | ||
makefile.vms | ||
missing | ||
mkdep | ||
mkinstalldirs | ||
move-if-change | ||
multilib.am | ||
README | ||
README-maintainer-mode | ||
setup.com | ||
src-release.sh | ||
symlink-tree | ||
test-driver | ||
ylwrap |
README for GNU development tools This directory contains various GNU compilers, assemblers, linkers, debuggers, etc., plus their support routines, definitions, and documentation. If you are receiving this as part of a GDB release, see the file gdb/README. If with a binutils release, see binutils/README; if with a libg++ release, see libg++/README, etc. That'll give you info about this package -- supported targets, how to use it, how to report bugs, etc. It is now possible to automatically configure and build a variety of tools with one command. To build all of the tools contained herein, run the ``configure'' script here, e.g.: ./configure make To install them (by default in /usr/local/bin, /usr/local/lib, etc), then do: make install (If the configure script can't determine your type of computer, give it the name as an argument, for instance ``./configure sun4''. You can use the script ``config.sub'' to test whether a name is recognized; if it is, config.sub translates it to a triplet specifying CPU, vendor, and OS.) If you have more than one compiler on your system, it is often best to explicitly set CC in the environment before running configure, and to also set CC when running make. For example (assuming sh/bash/ksh): CC=gcc ./configure make A similar example using csh: setenv CC gcc ./configure make Much of the code and documentation enclosed is copyright by the Free Software Foundation, Inc. See the file COPYING or COPYING.LIB in the various directories, for a description of the GNU General Public License terms under which you can copy the files. REPORTING BUGS: Again, see gdb/README, binutils/README, etc., for info on where and how to report problems.