From patchwork Tue Sep 16 23:30:42 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Evans X-Patchwork-Id: 2873 Received: (qmail 2231 invoked by alias); 16 Sep 2014 23:30:47 -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 2222 invoked by uid 89); 16 Sep 2014 23:30:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f74.google.com Received: from mail-pa0-f74.google.com (HELO mail-pa0-f74.google.com) (209.85.220.74) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 16 Sep 2014 23:30:45 +0000 Received: by mail-pa0-f74.google.com with SMTP id lj1so228973pab.5 for ; Tue, 16 Sep 2014 16:30:43 -0700 (PDT) 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=9v29bYlotl/3UF5R3AK+nt/yMVpws/HVcVJGLJybcfg=; b=OspjELhCvkaAPDxXMgKKMWwQjdKUgJY0CkcJ1CRa7ZydKag0w8RdfQao6vuX355aQI SgqQGj/EJPDM/oF/OMcSgvthg15N5GBoGcEV/X3cUMnvp3Ni+DgZt7GpNepvgVt3kPLJ Zez9f+e9mL7E6RgYEP/CD/GNqDDDhy0QdXHXSp8eXo8ibWVGRwXrZnxqIr/e0lg7tQ3N qdaHSlKVGVG3WgISK87TdgqvUULnose7LEJ9o7AxM7qRs3duBc15Rq19kBtGo6m6hbvr nt/kXIGbWYhHHku2M/i+qo7oTpH9FQ/wmXd4JejQdQYg756QmmsfU14VfbJBMeDhHEtm kYlg== X-Gm-Message-State: ALoCoQn1/oJOzuWDYH1QO87miCLQBYh4gd5xmYBXtAe6sJse3oZAvB8HkJuOJPotNEk8lyqrlm1W X-Received: by 10.68.196.161 with SMTP id in1mr21667371pbc.5.1410910243582; Tue, 16 Sep 2014 16:30:43 -0700 (PDT) Received: from corpmail-nozzle1-1.hot.corp.google.com ([100.108.1.104]) by gmr-mx.google.com with ESMTPS id n22si775244yhd.1.2014.09.16.16.30.43 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Sep 2014 16:30:43 -0700 (PDT) Received: from ruffy.mtv.corp.google.com ([172.17.128.44]) by corpmail-nozzle1-1.hot.corp.google.com with ESMTPS id dS8laciO.1; Tue, 16 Sep 2014 16:30:43 -0700 From: Doug Evans To: gdb-patches@sourceware.org, eliz@gnu.org Subject: [PATCH] New "producer" attribute for gdb.Symtab objects Date: Tue, 16 Sep 2014 16:30:42 -0700 Message-ID: MIME-Version: 1.0 X-IsSubscribed: yes Hi. I have a need to get the producer string from python. Regression tested on amd64-linux. Eli, this needs a doc RFA. 2014-09-16 Doug Evans * NEWS: Mention new "producer" attribute of gdb.Symtab. * python/py-symtab.c (stpy_get_producer): New function. (symtab_object_getset): Add "producer" attribute. doc/ * python.texi (Symbol Tables In Python): Document "producer" attribute of gdb.Symtab objects. testsuite/ * gdb.python/py-symtab.exp: Add test for symtab.producer. diff --git a/gdb/NEWS b/gdb/NEWS index 3bb1c74..e01ed71 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -4,7 +4,9 @@ *** Changes since GDB 7.8 * Python Scripting - You can now access frame registers from Python scripts. + + ** You can now access frame registers from Python scripts. + ** New attribute 'producer' for gdb.Symtab objects. * New Python-based convenience functions: diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index 9f44948..81ec11b 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -4043,6 +4043,14 @@ The symbol table's backing object file. @xref{Objfiles In Python}. This attribute is not writable. @end defvar +@defvar Symtab.producer +The name and possibly version number of the program that +compiled the code in the symbol table. +The contents of this string is up to the compiler. +If no producer information is available then @code{None} is returned. +This attribute is not writable. +@end defvar + A @code{gdb.Symtab} object has the following methods: @defun Symtab.is_valid () diff --git a/gdb/python/py-symtab.c b/gdb/python/py-symtab.c index 8f4208d..1065ba3 100644 --- a/gdb/python/py-symtab.c +++ b/gdb/python/py-symtab.c @@ -126,6 +126,25 @@ stpy_get_objfile (PyObject *self, void *closure) return result; } +/* Getter function for symtab.producer. */ + +static PyObject * +stpy_get_producer (PyObject *self, void *closure) +{ + struct symtab *symtab = NULL; + + STPY_REQUIRE_VALID (self, symtab); + if (symtab->producer != NULL) + { + const char *producer = symtab->producer; + + return PyString_Decode (producer, strlen (producer), + host_charset (), NULL); + } + + Py_RETURN_NONE; +} + static PyObject * stpy_fullname (PyObject *self, PyObject *args) { @@ -530,6 +549,8 @@ static PyGetSetDef symtab_object_getset[] = { "The symbol table's source filename.", NULL }, { "objfile", stpy_get_objfile, NULL, "The symtab's objfile.", NULL }, + { "producer", stpy_get_producer, NULL, + "The name/version of the program that compiled this symtab.", NULL }, {NULL} /* Sentinel */ }; diff --git a/gdb/testsuite/gdb.python/py-symtab.exp b/gdb/testsuite/gdb.python/py-symtab.exp index e6ac9c3..e2bd3d7 100644 --- a/gdb/testsuite/gdb.python/py-symtab.exp +++ b/gdb/testsuite/gdb.python/py-symtab.exp @@ -59,6 +59,15 @@ gdb_test "python print (sal.is_valid())" "True" "Test sal.is_valid" # Test symbol table. gdb_test "python print (symtab.filename)" ".*gdb.python/py-symbol.c.*" "Test symtab.filename" gdb_test "python print (symtab.objfile)" "" "Test symtab.objfile" +# We can't do much to test the producer string (compiler name+version). +# But we do have support for knowing whether gcc was used, so we can at +# least use that. +if { $gcc_compiled } { + set producer_regexp "GNU.*" +} else { + set producer_regexp "" +} +gdb_test "python print (symtab.producer)" "$producer_regexp" "Test symtab.producer" gdb_test "python print (symtab.fullname())" "testsuite/gdb.python/py-symbol.c.*" "Test symtab.fullname" gdb_test "python print (symtab.is_valid())" "True" "Test symtab.is_valid()" gdb_test "python print (\"qq\" in global_symbols)" "True" "Test qq in global symbols"