From patchwork Tue Jan 20 23:19:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Evans X-Patchwork-Id: 4743 Received: (qmail 24806 invoked by alias); 20 Jan 2015 23:19:43 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 24788 invoked by uid 89); 20 Jan 2015 23:19:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mail-ob0-f202.google.com Received: from mail-ob0-f202.google.com (HELO mail-ob0-f202.google.com) (209.85.214.202) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 20 Jan 2015 23:19:37 +0000 Received: by mail-ob0-f202.google.com with SMTP id va2so1516017obc.1 for ; Tue, 20 Jan 2015 15:19:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-type; bh=iuY1ERBYGdrpBO+pAmhNJwg7VTXg1c6IWmfh1oGJRQs=; b=gJyFKuVeGyRHuJp3dLqymCJ1JUQyaWq9sthBxIB+a/Ah/Y/ShoDp/dCbR7iwESNWch UhOfn0DGnbRRhh3huLPYqwDm6W78oEbnFV+THvGk/1mxZjvkQNtSetjlS6xt29mfTiIm cnNkiFAazR4RI8RPdWsW5WBOvSKI6hLv1iEYs/MFJeYFt1NKnn2ysgKI1aoiYOi+3n7G r/1g0yYAagGpJIy1SRaWCrH3oAPHfAPE3Hg5NEzrmGFutkbieDtowEqXYHpYts6RxnSp Q/43OxoLC55paYpO48x6BEexcfREuYUIYQBGSjLmr4a0xgrtQGfKUeKeIYa/xKX9dxIg pjXw== X-Gm-Message-State: ALoCoQn8dKeVQ4zpYxUCJGFynX6GQuWzQDm4QhZZSt+Cbaz91Mh3FAJZsJE12ulKBHYTFOhwSmVv X-Received: by 10.182.20.169 with SMTP id o9mr5996968obe.13.1421795975486; Tue, 20 Jan 2015 15:19:35 -0800 (PST) Received: from corpmail-nozzle1-1.hot.corp.google.com ([100.108.1.104]) by gmr-mx.google.com with ESMTPS id r4si300623qca.0.2015.01.20.15.19.35 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Jan 2015 15:19:35 -0800 (PST) Received: from ruffy.mtv.corp.google.com ([172.17.128.44]) by corpmail-nozzle1-1.hot.corp.google.com with ESMTPS id 5PFJt7SQ.1; Tue, 20 Jan 2015 15:19:35 -0800 From: Doug Evans To: gdb-patches@sourceware.org, eliz@gnu.org Subject: [PATCH 2/2] Add objfile.username Date: Tue, 20 Jan 2015 15:19:34 -0800 Message-ID: MIME-Version: 1.0 X-IsSubscribed: yes Hi. I have a need to expose objfile->original_name to python, this patch implements the feature. 2015-01-20 Doug Evans * 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
" \ "print main with debug info"