From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14323 invoked by alias); 10 Jun 2009 21:33:32 -0000 Received: (qmail 14313 invoked by uid 22791); 10 Jun 2009 21:33:31 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_33 X-Spam-Check-By: sourceware.org Received: from fmmailgate02.web.de (HELO fmmailgate02.web.de) (217.72.192.227) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 10 Jun 2009 21:33:25 +0000 Received: from smtp05.web.de (fmsmtp05.dlan.cinetic.de [172.20.4.166]) by fmmailgate02.web.de (Postfix) with ESMTP id 85EE91028D8D8; Wed, 10 Jun 2009 23:33:23 +0200 (CEST) Received: from [88.64.26.191] (helo=[192.168.1.10]) by smtp05.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #277) id 1MEVQA-0002gW-00; Wed, 10 Jun 2009 23:33:22 +0200 Message-ID: <4A30269D.7070504@web.de> Date: Wed, 10 Jun 2009 21:33:00 -0000 From: Jan Kiszka User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666 MIME-Version: 1.0 To: tromey@redhat.com CC: gdb@sourceware.org Subject: Re: container_of equivalent in gdb-python script References: <4A2FE5AB.4060707@siemens.com> <4A30133F.9000909@web.de> <20090610204201.GA17154@caradoc.them.org> In-Reply-To: <20090610204201.GA17154@caradoc.them.org> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig7EBABD19E781101C458B486F" X-Sender: jan.kiszka@web.de Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2009-06/txt/msg00099.txt.bz2 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig7EBABD19E781101C458B486F Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-length: 2443 Daniel Jacobowitz wrote: > On Wed, Jun 10, 2009 at 10:10:39PM +0200, Jan Kiszka wrote: >> I want to automate 'add-symbol-file linux_module.ko 0xff...' that you >> have to run for loading the symbols of dynamically loaded kernel >> modules. Before that you also have to look up the module base address, >> typically by cat'ing /proc/modules on the target. With a proper python >> script, this will be trivial to do automatically. You just have to walk >> the module list of the kernel you are attached to, extract names and >> base addresses, search for the corresponding module binaries (also easy >> with python) and issue the proper add-symbol-file commands. >=20 > FYI, I am hoping to work on this soon (in the next month). The right > representation is not a set of add-symbol-file commands, which doesn't > play nicely with repeated unload/reload, but instead a synthetic list Currently, I does. I simply reload the whole set of symbols (vmlinux + modules) when requested by the user. Of course, one could additionally register a triggering breakpoint on return of load_module(), but having a simple helper that can be called on demand will already be a great improvement. > of shared libraries. That calls for some extensions to the current > set of Python hooks and shared library infrastructure, though! And it > will require basically everything you're doing now :-) Looking forward nevertheless. What ever makes kernel debugging more handy is welcome. Once finished, I will post my script here. >=20 >> But now back to the core problems, starting with the exercise to >> implement offset_of(type, field): >> >> def offset_of(type, field): >> container_type =3D gdb.lookup_type(type) >> dummy_obj =3D gdb.selected_frame().read_var('modules') >> container_obj =3D dummy_obj.cast(container_type) >> field_obj =3D container_obj[field] >> return int(str(field_obj.address), 16) - \ >> int(str(container_obj.address), 16) >> >> I meanwhile discovered (reading testcases and python-*.c) >> gdb.lookup_type() and Value.cast() to make this real. But you see, I >> still need an ugly synthetic Value object which must have a non-'None' >> address to do this calculation. Is there a cleaner, more generic way? >=20 > It's typical to do this the same way folks do in C: Create a null > pointer of the right type. You can't do that with the current upstream python interface, but the parse_and_eval solves this nicely. Jan --------------enig7EBABD19E781101C458B486F Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" Content-length: 257 -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iEYEARECAAYFAkowJqEACgkQniDOoMHTA+kLbACeL9dNnajANL+TlaxDaZ/RoTjO MyoAn2kmifBLXq4Nqw33PxnK0sY1uYvQ =iLbB -----END PGP SIGNATURE----- --------------enig7EBABD19E781101C458B486F--