Add gdb.Objfile.username.

gdb/ChangeLog:

	* NEWS: Mention gdb.Objfile.username.
	* python/py-objfile.c (objfpy_get_username): New function.
	(objfile_getset): Add "username".

gdb/doc/ChangeLog:

	* python.texi (Objfiles In Python): Document Objfile.username.

gdb/testsuite/ChangeLog:

	* gdb.python/py-objfile.exp: Add tests for objfile.username.
	Add test for objfile.filename, objfile.username after objfile
	has been unloaded.
This commit is contained in:
Doug Evans 2015-01-27 10:13:52 -08:00
parent 1b5493961a
commit 3a8b707add
7 changed files with 68 additions and 0 deletions

View file

@ -1,3 +1,9 @@
2015-01-27 Doug Evans <dje@google.com>
* NEWS: Mention gdb.Objfile.username.
* python/py-objfile.c (objfpy_get_username): New function.
(objfile_getset): Add "username".
2015-01-24 Mark Wielaard <mjw@redhat.com> 2015-01-24 Mark Wielaard <mjw@redhat.com>
* stack.c (return_command): Markup warning message with _. * stack.c (return_command): Markup warning message with _.

View file

@ -3,6 +3,12 @@
*** Changes since GDB 7.9 *** Changes since GDB 7.9
* Python Scripting
** gdb.Objfile objects have a new attribute "username",
which is the name of the objfile as specified by the user,
without, for example, resolving symlinks.
* New options * New options
* The command 'thread apply all' can now support new option '-ascending' * The command 'thread apply all' can now support new option '-ascending'

View file

@ -1,3 +1,7 @@
2015-01-27 Doug Evans <dje@google.com>
* python.texi (Objfiles In Python): Document Objfile.username.
2015-01-27 Doug Evans <dje@google.com> 2015-01-27 Doug Evans <dje@google.com>
* python.texi (Objfiles In Python) <Objfile.filename>: Improve docs. * python.texi (Objfiles In Python) <Objfile.filename>: Improve docs.

View file

@ -3519,6 +3519,13 @@ The value is @code{None} if the objfile is no longer valid.
See the @code{gdb.Objfile.is_valid} method, described below. See the @code{gdb.Objfile.is_valid} method, described below.
@end defvar @end defvar
@defvar Objfile.username
The file name of the objfile as specified by the user as a string.
The value is @code{None} if the objfile is no longer valid.
See the @code{gdb.Objfile.is_valid} method, described below.
@end defvar
@defvar Objfile.owner @defvar Objfile.owner
For separate debug info objfiles this is the corresponding @code{gdb.Objfile} For separate debug info objfiles this is the corresponding @code{gdb.Objfile}
object that debug info is being provided for. object that debug info is being provided for.

View file

@ -81,6 +81,25 @@ objfpy_get_filename (PyObject *self, void *closure)
Py_RETURN_NONE; Py_RETURN_NONE;
} }
/* An Objfile method which returns the objfile's file name, as specified
by the user, or None. */
static PyObject *
objfpy_get_username (PyObject *self, void *closure)
{
objfile_object *obj = (objfile_object *) self;
if (obj->objfile)
{
const char *username = obj->objfile->original_name;
return PyString_Decode (username, strlen (username),
host_charset (), NULL);
}
Py_RETURN_NONE;
}
/* If SELF is a separate debug-info file, return the "backlink" field. /* If SELF is a separate debug-info file, return the "backlink" field.
Otherwise return None. */ Otherwise return None. */
@ -613,6 +632,8 @@ static PyGetSetDef objfile_getset[] =
"The __dict__ for this objfile.", &objfile_object_type }, "The __dict__ for this objfile.", &objfile_object_type },
{ "filename", objfpy_get_filename, NULL, { "filename", objfpy_get_filename, NULL,
"The objfile's filename, or None.", NULL }, "The objfile's filename, or None.", NULL },
{ "username", objfpy_get_username, NULL,
"The name of the objfile as provided by the user, or None.", NULL },
{ "owner", objfpy_get_owner, NULL, { "owner", objfpy_get_owner, NULL,
"The objfile owner of separate debug info objfiles, or None.", "The objfile owner of separate debug info objfiles, or None.",
NULL }, NULL },

View file

@ -1,3 +1,9 @@
2015-01-27 Doug Evans <dje@google.com>
* gdb.python/py-objfile.exp: Add tests for objfile.username.
Add test for objfile.filename, objfile.username after objfile
has been unloaded.
2015-01-26 Joel Brobecker <brobecker@adacore.com> 2015-01-26 Joel Brobecker <brobecker@adacore.com>
* gdb.python/py-lookup-type.exp (test_lookup_type): Change * gdb.python/py-lookup-type.exp (test_lookup_type): Change

View file

@ -42,6 +42,9 @@ gdb_py_test_silent_cmd "python objfile = sym\[0\].symtab.objfile" \
gdb_test "python print (objfile.filename)" "${testfile}" \ gdb_test "python print (objfile.filename)" "${testfile}" \
"Get objfile file name" "Get objfile file name"
gdb_test "python print (objfile.username)" "${testfile}" \
"Get objfile user name"
gdb_test "python print (gdb.lookup_objfile (\"${testfile}\").filename)" \ gdb_test "python print (gdb.lookup_objfile (\"${testfile}\").filename)" \
"${testfile}" "${testfile}"
gdb_test "python print (gdb.lookup_objfile (\"junk\"))" \ gdb_test "python print (gdb.lookup_objfile (\"junk\"))" \
@ -78,6 +81,18 @@ gdb_py_test_silent_cmd "python objfile.random_attribute = 42" \
gdb_test "python print (objfile.random_attribute)" "42" \ gdb_test "python print (objfile.random_attribute)" "42" \
"Verify set of random attribute in objfile" "Verify set of random attribute in objfile"
# Verify invalid objfile handling.
if { [gdb_unload] < 0 } {
fail "unload all files"
return -1
}
gdb_test "python print objfile.filename" "None" \
"objfile.filename after objfile is unloaded"
gdb_test "python print objfile.username" "None" \
"objfile.username after objfile is unloaded"
# Now build another copy of the testcase, this time without debug info. # Now build another copy of the testcase, this time without debug info.
if { [prepare_for_testing ${testfile}.exp ${testfile}2 ${srcfile} {nodebug ldflags=-Wl,--strip-debug}] } { if { [prepare_for_testing ${testfile}.exp ${testfile}2 ${srcfile} {nodebug ldflags=-Wl,--strip-debug}] } {
@ -107,6 +122,9 @@ gdb_py_test_silent_cmd "python sep_objfile = gdb.objfiles()\[0\]" \
gdb_test "python print (sep_objfile.owner.filename)" "${testfile}2" \ gdb_test "python print (sep_objfile.owner.filename)" "${testfile}2" \
"Test owner of separate debug file" "Test owner of separate debug file"
gdb_test "python print (sep_objfile.owner.username)" "${testfile}2" \
"Test user-name of owner of separate debug file"
gdb_test "p main" "= {int \\(\\)} $hex <main>" \ gdb_test "p main" "= {int \\(\\)} $hex <main>" \
"print main with debug info" "print main with debug info"