From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31833 invoked by alias); 9 Oct 2014 18:54:40 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 31822 invoked by uid 89); 9 Oct 2014 18:54:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL,BAYES_00,MIME_BASE64_BLANKS,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 X-HELO: na01-bn1-obe.outbound.protection.outlook.com Received: from mail-bn1bon0084.outbound.protection.outlook.com (HELO na01-bn1-obe.outbound.protection.outlook.com) (157.56.111.84) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Thu, 09 Oct 2014 18:54:37 +0000 Received: from BY2FFO11FD017.protection.gbl (10.1.14.32) by BY2FFO11HUB017.protection.gbl (10.1.14.91) with Microsoft SMTP Server (TLS) id 15.0.1039.16; Thu, 9 Oct 2014 18:54:33 +0000 Received: from xsj-pvapsmtpgw01 (149.199.60.83) by BY2FFO11FD017.mail.protection.outlook.com (10.1.14.105) with Microsoft SMTP Server (TLS) id 15.0.1039.16 via Frontend Transport; Thu, 9 Oct 2014 18:54:33 +0000 Received: from unknown-38-66.xilinx.com ([149.199.38.66] helo=xsj-smtp1) by xsj-pvapsmtpgw01 with esmtp (Exim 4.63) (envelope-from ) id 1XcIpT-0005kD-NW; Thu, 09 Oct 2014 11:52:47 -0700 From: Ajit Kumar Agarwal To: Michael Eager , Pedro Alves , Joel Brobecker CC: "gdb-patches@sourceware.org" , Vinod Kathail , Vidhumouli Hunsigida , "Nagaraju Mekala" Subject: RE: [Patch] Microblaze: Port of Linux gdbserver Date: Thu, 09 Oct 2014 18:54:00 -0000 References: <25de23b98e054fd291ea232d10f2800c@BN1BFFO11FD018.protection.gbl> <5436B7D0.9060004@eagercon.com> In-Reply-To: <5436B7D0.9060004@eagercon.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: base64 MIME-Version: 1.0 X-RCIS-Action: ALLOW Message-ID: X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:149.199.60.83;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(438002)(189002)(377454003)(199003)(479174003)(13464003)(377424004)(51704005)(24454002)(2656002)(85852003)(76482002)(15975445006)(54356999)(92566001)(77096002)(53416004)(87936001)(95666004)(50986999)(120916001)(106466001)(86362001)(4396001)(50466002)(106116001)(108616004)(21056001)(6806004)(74316001)(104016003)(76176999)(64706001)(107046002)(99396003)(19580405001)(44976005)(80022003)(46102003)(20776003)(23676002)(31966008)(19580395003)(47776003)(85306004)(107986001)(24736002)(23106004);DIR:OUT;SFP:1101;SCL:1;SRVR:BY2FFO11HUB017;H:xsj-pvapsmtpgw01;FPR:;MLV:sfv;PTR:unknown-60-83.xilinx.com;MX:1;A:1;LANG:en; X-Microsoft-Antispam: UriScan:; X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;SRVR:BY2FFO11HUB017; X-Forefront-PRVS: 0359162B6D Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.60.83 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.60.83; helo=xsj-pvapsmtpgw01; Authentication-Results: spf=pass (sender IP is 149.199.60.83) smtp.mailfrom=ajit.kumar.agarwal@xilinx.com; X-OriginatorOrg: xilinx.com X-SW-Source: 2014-10/txt/msg00220.txt.bz2 DQoNCi0tLS0tT3JpZ2luYWwgTWVzc2FnZS0tLS0tDQpGcm9tOiBNaWNoYWVs IEVhZ2VyIFttYWlsdG86ZWFnZXJAZWFnZXJjb24uY29tXSANClNlbnQ6IFRo dXJzZGF5LCBPY3RvYmVyIDA5LCAyMDE0IDk6NTkgUE0NClRvOiBBaml0I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ZXMgdGhpcyBmaWxlLCBpbiBhIG5ldyB0 aHJlYWQsIA0KPiB3aXRoIHNlbGYtY29udGFpbmVkIGRlc2NyaXB0aW9uLCBm b2xsb3dpbmcgdGhlDQo+IGNoZWNrbGlzdDoNCj4gICBodHRwczovL3NvdXJj ZXdhcmUub3JnL2dkYi93aWtpL0NvbnRyaWJ1dGlvbkNoZWNrbGlzdA0KDQo+ PlByZXBhcmF0b3J5IG1lYW5zIHRoYXQgdGhlIHBhdGNoIHNob3VsZCBiZSBz dWJtaXR0ZWQgYmVmb3JlIHRoZSBjdXJyZW50IHBhdGNoLg0KDQpJIHdpbGwg YmUgc2VuZGluZyB0aGlzIHBhdGNoIHNvb24uDQoNClRoYW5rcyAmIFJlZ2Fy ZHMNCkFqaXQNCg0KLS0gDQpNaWNoYWVsIEVhZ2VyCSBlYWdlckBlYWdlcmNv bi5jb20NCjE5NjAgUGFyayBCbHZkLiwgUGFsbyBBbHRvLCBDQSA5NDMwNiAg NjUwLTMyNS04MDc3DQo= >From gdb-patches-return-116545-listarch-gdb-patches=sources.redhat.com@sourceware.org Thu Oct 09 19:08:14 2014 Return-Path: Delivered-To: listarch-gdb-patches@sources.redhat.com Received: (qmail 7784 invoked by alias); 9 Oct 2014 19:08:14 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 7772 invoked by uid 89); 9 Oct 2014 19:08:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.1 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-ig0-f201.google.com Received: from mail-ig0-f201.google.com (HELO mail-ig0-f201.google.com) (209.85.213.201) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 09 Oct 2014 19:08:12 +0000 Received: by mail-ig0-f201.google.com with SMTP id h15so841608igd.4 for ; Thu, 09 Oct 2014 12:08:10 -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=qDgNC5p+wniLlcy9aivJLPZkkrJ1R+/oT9QRCuIQlQg=; b=X0Iomqs3GX9WLb7UF5s4oBomPIphm+NtKX0jO5wAXfYGHtBk29HLiXarIKm0IllEtE j/+hPrr4fRf8EZZArNqQOTOV+OIZ1w1qu1bGteDdjSoz9LqHpA5GTU2jpBgnbLhosezu 54sXHcWD/muy3SUdWblscoOXlnCvZMRnHLsHPHUfg7oS+9Y8Z/f7Eq1oHnwumdXhY23o CbsoDlK627snzLMw0EHAVPveQYyGuiUCoy4zFFak9TbKmH7IUNQ0FUJVyrbexWIoLYLX 7wMW19PDvCqLkHwoS1BGjo0V/SpPMtTnaSKsHbBzWQAJrY+T6gwaNEasitzroacqsBOH NL1w== X-Gm-Message-State: ALoCoQkyh6uNMnSKEwu+MJ8EgA6j+hsNIBASRScL9ulodTgqhaTeRAqUlTlggH24jzNWOJoMVwFf X-Received: by 10.50.43.168 with SMTP id x8mr132953igl.4.1412881690070; Thu, 09 Oct 2014 12:08:10 -0700 (PDT) Received: from corpmail-nozzle1-2.hot.corp.google.com ([100.108.1.103]) by gmr-mx.google.com with ESMTPS id l45si210926yha.2.2014.10.09.12.08.09 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Oct 2014 12:08:10 -0700 (PDT) Received: from ruffy.mtv.corp.google.com ([172.17.128.44]) by corpmail-nozzle1-2.hot.corp.google.com with ESMTPS id vsIt03mS.1; Thu, 09 Oct 2014 12:08:09 -0700 From: Doug Evans To: gdb-patches@sourceware.org, eliz@gnu.org Subject: [PATCH, doc RFA] Add ability to set random attributes in python objfiles,progspaces Date: Thu, 09 Oct 2014 19:08:00 -0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes X-SW-Source: 2014-10/txt/msg00221.txt.bz2 Content-length: 7711 Hi. I have a need to do some extra record keeping in progspaces and objfiles. This patch adds the ability to add random attributes to objfile and progspace objects using the same mechanism used for gdb.Fields. Regression tested on amd64-linux. 2014-10-09 Doug Evans * NEWS: Mention ability add attributes to gdb.Objfile and gdb.Progspace objects. * python/py-objfile.c (objfile_object): New member dict. (objfpy_dealloc): Py_XDECREF dict. (objfpy_initialize): Initialize dict. (objfile_getset): Add __dict__. (objfile_object_type): Set tp_dictoffset member. * python/py-progspace.c (progspace_object): New member dict. (pspy_dealloc): Py_XDECREF dict. (pspy_initialize): Initialize dict. (pspace_getset): Add __dict__. (pspace_object_type): Set tp_dictoffset member. doc/ * gdb.texinfo (Progspaces In Python): Document ability to add random attributes to gdb.Progspace objects. (Objfiles In Python): Document ability to add random attributes to gdb.objfile objects. testsuite/ * gdb.python/py-objfile.exp: Add tests for setting random attributes in objfiles. * gdb.python/py-progspace.exp: Add tests for setting random attributes in progspaces. diff --git a/gdb/NEWS b/gdb/NEWS index b56fe8e..ec43a22 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -9,6 +9,7 @@ ** You can now access frame registers from Python scripts. ** New attribute 'producer' for gdb.Symtab objects. + ** You can now add attributes to gdb.Objfile and gdb.Progspace objects. * New Python-based convenience functions: diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index 81ec11b..14a2181 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -3356,6 +3356,10 @@ The @code{frame_filters} attribute is a dictionary of frame filter objects. @xref{Frame Filter API}, for more information. @end defvar +One may add arbitrary attributes to @code{gdb.Progspace} objects. +This is useful if for example one needs to do some extra record keeping +associated with the progspace. + @node Objfiles In Python @subsubsection Objfiles In Python @@ -3411,6 +3415,26 @@ The @code{frame_filters} attribute is a dictionary of frame filter objects. @xref{Frame Filter API}, for more information. @end defvar +One may add arbitrary attributes to @code{gdb.Objfile} objects. +This is useful if for example one needs to do some extra record keeping +associated with the objfile. + +In this contrived example we record the time when @value{GDBN} +loaded the objfile. + +@smallexample +(gdb) python +import datetime +def new_objfile_handler (event): + event.new_objfile.time_loaded = datetime.datetime.today () +gdb.events.new_objfile.connect (new_objfile_handler) +end +(gdb) file ./hello +Reading symbols from ./hello...done. +(gdb) python print gdb.objfiles()[0].time_loaded +2014-10-09 11:41:36.770345 +@end smallexample + A @code{gdb.Objfile} object has the following methods: @defun Objfile.is_valid () diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c index df29691..32bceee 100644 --- a/gdb/python/py-objfile.c +++ b/gdb/python/py-objfile.c @@ -30,6 +30,9 @@ typedef struct /* The corresponding objfile. */ struct objfile *objfile; + /* Dictionary holding user-added attributes. */ + PyObject *dict; + /* The pretty-printer list of functions. */ PyObject *printers; @@ -67,6 +70,7 @@ objfpy_dealloc (PyObject *o) { objfile_object *self = (objfile_object *) o; + Py_XDECREF (self->dict); Py_XDECREF (self->printers); Py_XDECREF (self->frame_filters); Py_XDECREF (self->type_printers); @@ -81,6 +85,7 @@ static int objfpy_initialize (objfile_object *self) { self->objfile = NULL; + self->dict = NULL; self->printers = PyList_New (0); if (self->printers == NULL) @@ -336,6 +341,8 @@ Return true if this object file is valid, false if not." }, static PyGetSetDef objfile_getset[] = { + { "__dict__", gdb_py_generic_dict, NULL, + "The __dict__ for this objfile.", &objfile_object_type }, { "filename", objfpy_get_filename, NULL, "The objfile's filename, or None.", NULL }, { "pretty_printers", objfpy_get_printers, objfpy_set_printers, @@ -385,7 +392,7 @@ static PyTypeObject objfile_object_type = 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ + offsetof (objfile_object, dict), /* tp_dictoffset */ 0, /* tp_init */ 0, /* tp_alloc */ objfpy_new, /* tp_new */ diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c index 4280032..72ed353 100644 --- a/gdb/python/py-progspace.c +++ b/gdb/python/py-progspace.c @@ -32,6 +32,9 @@ typedef struct /* The corresponding pspace. */ struct program_space *pspace; + /* Dictionary holding user-added attributes. */ + PyObject *dict; + /* The pretty-printer list of functions. */ PyObject *printers; @@ -75,6 +78,7 @@ pspy_dealloc (PyObject *self) { pspace_object *ps_self = (pspace_object *) self; + Py_XDECREF (ps_self->dict); Py_XDECREF (ps_self->printers); Py_XDECREF (ps_self->frame_filters); Py_XDECREF (ps_self->type_printers); @@ -89,6 +93,7 @@ static int pspy_initialize (pspace_object *self) { self->pspace = NULL; + self->dict = NULL; self->printers = PyList_New (0); if (self->printers == NULL) @@ -331,6 +336,8 @@ gdbpy_initialize_pspace (void) static PyGetSetDef pspace_getset[] = { + { "__dict__", gdb_py_generic_dict, NULL, + "The __dict__ for this progspace.", &pspace_object_type }, { "filename", pspy_get_filename, NULL, "The progspace's main filename, or None.", NULL }, { "pretty_printers", pspy_get_printers, pspy_set_printers, @@ -380,7 +387,7 @@ static PyTypeObject pspace_object_type = 0, /* tp_dict */ 0, /* tp_descr_get */ 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ + offsetof (pspace_object, dict), /* tp_dictoffset */ 0, /* tp_init */ 0, /* tp_alloc */ pspy_new, /* tp_new */ diff --git a/gdb/testsuite/gdb.python/py-objfile.exp b/gdb/testsuite/gdb.python/py-objfile.exp index 56f99f8..d880da3 100644 --- a/gdb/testsuite/gdb.python/py-objfile.exp +++ b/gdb/testsuite/gdb.python/py-objfile.exp @@ -44,3 +44,8 @@ gdb_test "python print (objfile.is_valid())" "True" \ gdb_unload gdb_test "python print (objfile.is_valid())" "False" \ "Get objfile validity after unload" + +gdb_py_test_silent_cmd "python objfile.random_attribute = 42" \ + "Set random attribute in objfile" 1 +gdb_test "python print (objfile.random_attribute)" "42" \ + "Verify set of random attribute in objfile" diff --git a/gdb/testsuite/gdb.python/py-progspace.exp b/gdb/testsuite/gdb.python/py-progspace.exp index 2fcfdb9..a47fae6 100644 --- a/gdb/testsuite/gdb.python/py-progspace.exp +++ b/gdb/testsuite/gdb.python/py-progspace.exp @@ -16,6 +16,8 @@ # This file is part of the GDB testsuite. It tests the program space # support in Python. +load_lib gdb-python.exp + standard_testfile if {[build_executable $testfile.exp $testfile $srcfile debug] == -1} { @@ -37,5 +39,13 @@ gdb_test "python print (gdb.progspaces())" "\\\[\\ gdb_load ${binfile} -gdb_test "python print (gdb.current_progspace().filename)" "py-progspace" \ +gdb_py_test_silent_cmd "python progspace = gdb.current_progspace()" \ + "Get current progspace" 1 + +gdb_test "python print (progspace.filename)" "py-progspace" \ "current progspace filename (py-progspace)" + +gdb_py_test_silent_cmd "python progspace.random_attribute = 42" \ + "Set random attribute in progspace" 1 +gdb_test "python print (progspace.random_attribute)" "42" \ + "Verify set of random attribute in progspace"