* [PATCH 2/2] Add objfile.username
@ 2015-01-20 23:19 Doug Evans
2015-01-21 0:29 ` Doug Evans
2015-01-21 3:43 ` Eli Zaretskii
0 siblings, 2 replies; 5+ messages in thread
From: Doug Evans @ 2015-01-20 23:19 UTC (permalink / raw)
To: gdb-patches, eliz
Hi.
I have a need to expose objfile->original_name to python,
this patch implements the feature.
2015-01-20 Doug Evans <dje@google.com>
* NEWS: Mention gdb.Objfile.username.
* python/py-objfile.c (objfpy_get_username): New function.
(objfile_getset): Add "username".
doc/
* python.texi (Objfiles In Python): Document Objfile.username.
testsuite/
* gdb.python/py-objfile.exp: Add tests for objfile.username.
diff --git a/gdb/NEWS b/gdb/NEWS
index 2d2c941..a6fa35f 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,12 @@
*** 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.
+
*** Changes in GDB 7.9
* GDB now supports hardware watchpoints on x86 GNU Hurd.
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index b9a50d0..4389d3e 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -3516,6 +3516,13 @@ class.
The file name of the objfile as a string.
@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
For separate debug info objfiles this is the corresponding @code{gdb.Objfile}
object that debug info is being provided for.
diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
index 378db58..926066b 100644
--- a/gdb/python/py-objfile.c
+++ b/gdb/python/py-objfile.c
@@ -81,6 +81,21 @@ objfpy_get_filename (PyObject *self, void *closure)
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;
+ const char *username = obj->objfile->original_name;
+
+ if (obj->objfile)
+ return PyString_Decode (username, strlen (username),
+ host_charset (), NULL);
+ Py_RETURN_NONE;
+}
+
/* If SELF is a separate debug-info file, return the "backlink" field.
Otherwise return None. */
@@ -613,6 +628,8 @@ static PyGetSetDef objfile_getset[] =
"The __dict__ for this objfile.", &objfile_object_type },
{ "filename", objfpy_get_filename, 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,
"The objfile owner of separate debug info objfiles, or None.",
NULL },
diff --git a/gdb/testsuite/gdb.python/py-objfile.exp b/gdb/testsuite/gdb.python/py-objfile.exp
index cddbd3d..c7fa817 100644
--- a/gdb/testsuite/gdb.python/py-objfile.exp
+++ b/gdb/testsuite/gdb.python/py-objfile.exp
@@ -42,6 +42,9 @@ gdb_py_test_silent_cmd "python objfile = sym\[0\].symtab.objfile" \
gdb_test "python print (objfile.filename)" "${testfile}" \
"Get objfile file name"
+gdb_test "python print (objfile.username)" "${testfile}" \
+ "Get objfile user name"
+
gdb_test "python print (gdb.lookup_objfile (\"${testfile}\").filename)" \
"${testfile}"
gdb_test "python print (gdb.lookup_objfile (\"junk\"))" \
@@ -107,6 +110,9 @@ gdb_py_test_silent_cmd "python sep_objfile = gdb.objfiles()\[0\]" \
gdb_test "python print (sep_objfile.owner.filename)" "${testfile}2" \
"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>" \
"print main with debug info"
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] Add objfile.username
2015-01-20 23:19 [PATCH 2/2] Add objfile.username Doug Evans
@ 2015-01-21 0:29 ` Doug Evans
2015-01-21 3:45 ` Eli Zaretskii
2015-01-21 3:43 ` Eli Zaretskii
1 sibling, 1 reply; 5+ messages in thread
From: Doug Evans @ 2015-01-21 0:29 UTC (permalink / raw)
To: gdb-patches, eliz
Doug Evans writes:
> Hi.
>
> I have a need to expose objfile->original_name to python,
> this patch implements the feature.
>
> 2015-01-20 Doug Evans <dje@google.com>
>
> * NEWS: Mention gdb.Objfile.username.
> * python/py-objfile.c (objfpy_get_username): New function.
> (objfile_getset): Add "username".
>
> doc/
> * python.texi (Objfiles In Python): Document Objfile.username.
>
> testsuite/
> * gdb.python/py-objfile.exp: Add tests for objfile.username.
Heh.
This replaces the previous version.
Thinko in assigning username too soon.
+ const char *username = obj->objfile->original_name;
2015-01-20 Doug Evans <dje@google.com>
* NEWS: Mention gdb.Objfile.username.
* python/py-objfile.c (objfpy_get_username): New function.
(objfile_getset): Add "username".
doc/
* python.texi (Objfiles In Python): Document Objfile.username.
testsuite/
* gdb.python/py-objfile.exp: Add tests for objfile.username.
Add test for objfile.filename, objfile.username after objfile
has been unloaded.
diff --git a/gdb/NEWS b/gdb/NEWS
index 2d2c941..a6fa35f 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,12 @@
*** 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.
+
*** Changes in GDB 7.9
* GDB now supports hardware watchpoints on x86 GNU Hurd.
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index b9a50d0..4389d3e 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -3516,6 +3516,13 @@ class.
The file name of the objfile as a string.
@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
For separate debug info objfiles this is the corresponding @code{gdb.Objfile}
object that debug info is being provided for.
diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
index 378db58..0aecaf6 100644
--- a/gdb/python/py-objfile.c
+++ b/gdb/python/py-objfile.c
@@ -81,6 +81,25 @@ objfpy_get_filename (PyObject *self, void *closure)
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.
Otherwise return None. */
@@ -613,6 +632,8 @@ static PyGetSetDef objfile_getset[] =
"The __dict__ for this objfile.", &objfile_object_type },
{ "filename", objfpy_get_filename, 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,
"The objfile owner of separate debug info objfiles, or None.",
NULL },
diff --git a/gdb/testsuite/gdb.python/py-objfile.exp b/gdb/testsuite/gdb.python/py-objfile.exp
index cddbd3d..b53f5e3 100644
--- a/gdb/testsuite/gdb.python/py-objfile.exp
+++ b/gdb/testsuite/gdb.python/py-objfile.exp
@@ -42,6 +42,9 @@ gdb_py_test_silent_cmd "python objfile = sym\[0\].symtab.objfile" \
gdb_test "python print (objfile.filename)" "${testfile}" \
"Get objfile file name"
+gdb_test "python print (objfile.username)" "${testfile}" \
+ "Get objfile user name"
+
gdb_test "python print (gdb.lookup_objfile (\"${testfile}\").filename)" \
"${testfile}"
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" \
"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.
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" \
"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>" \
"print main with debug info"
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] Add objfile.username
2015-01-20 23:19 [PATCH 2/2] Add objfile.username Doug Evans
2015-01-21 0:29 ` Doug Evans
@ 2015-01-21 3:43 ` Eli Zaretskii
1 sibling, 0 replies; 5+ messages in thread
From: Eli Zaretskii @ 2015-01-21 3:43 UTC (permalink / raw)
To: Doug Evans; +Cc: gdb-patches
> From: Doug Evans <dje@google.com>
> Date: Tue, 20 Jan 2015 15:19:34 -0800
>
> I have a need to expose objfile->original_name to python,
> this patch implements the feature.
>
> 2015-01-20 Doug Evans <dje@google.com>
>
> * NEWS: Mention gdb.Objfile.username.
> * python/py-objfile.c (objfpy_get_username): New function.
> (objfile_getset): Add "username".
>
> doc/
> * python.texi (Objfiles In Python): Document Objfile.username.
>
> testsuite/
> * gdb.python/py-objfile.exp: Add tests for objfile.username.
OK for the documentation parts.
Thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] Add objfile.username
2015-01-21 0:29 ` Doug Evans
@ 2015-01-21 3:45 ` Eli Zaretskii
2015-01-27 21:31 ` Doug Evans
0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2015-01-21 3:45 UTC (permalink / raw)
To: Doug Evans; +Cc: gdb-patches
> From: Doug Evans <dje@google.com>
> Date: Tue, 20 Jan 2015 16:28:54 -0800
>
> Heh.
> This replaces the previous version.
> Thinko in assigning username too soon.
I see no differences in the documentation parts, so this is also okay
from my POV.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] Add objfile.username
2015-01-21 3:45 ` Eli Zaretskii
@ 2015-01-27 21:31 ` Doug Evans
0 siblings, 0 replies; 5+ messages in thread
From: Doug Evans @ 2015-01-27 21:31 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: gdb-patches
On Tue, Jan 20, 2015 at 7:44 PM, Eli Zaretskii <eliz@gnu.org> wrote:
>> From: Doug Evans <dje@google.com>
>> Date: Tue, 20 Jan 2015 16:28:54 -0800
>>
>> Heh.
>> This replaces the previous version.
>> Thinko in assigning username too soon.
>
> I see no differences in the documentation parts, so this is also okay
> from my POV.
Committed, thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-01-27 18:15 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-20 23:19 [PATCH 2/2] Add objfile.username Doug Evans
2015-01-21 0:29 ` Doug Evans
2015-01-21 3:45 ` Eli Zaretskii
2015-01-27 21:31 ` Doug Evans
2015-01-21 3:43 ` Eli Zaretskii
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).