From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0F063396E052; Wed, 2 Dec 2020 21:18:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0F063396E052 From: "jwakely.gcc at gmail dot com" To: gdb-prs@sourceware.org Subject: [Bug python/27000] gdb.block_for_pc should accept a gdb.Value argument Date: Wed, 02 Dec 2020 21:18:17 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gdb X-Bugzilla-Component: python X-Bugzilla-Version: 10.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jwakely.gcc at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gdb-prs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-prs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Dec 2020 21:18:18 -0000 https://sourceware.org/bugzilla/show_bug.cgi?id=3D27000 --- Comment #1 from Jonathan Wakely --- (In reply to Jonathan Wakely from comment #0) > - Calling int with gdb.Value should not raise an exception if long(v) wou= ld > work instead, just do that. >=20 > - gdb.block_for_pc should not raise exceptions for invalid values, or the > docs should be fixed. Actually it looks like these two are already done for GDB 10.1, I must have tested with the wrong version, sorry. But it would still be easier if I could use a gdb.Value directly. Testcase: int function () { int (*p)() =3D &function; return 0; } int main() { return function(1); } On ppc64 running CentOS 7, with the system Python (2.7) and GDB 10.1 I get: (gdb) start Starting program: /home/jwakely/tmp/a.out=20 Temporary breakpoint 2, main () at b.c:8 8 return function(1); (gdb) step function () at b.c:3 3 int (*p)() =3D &function; (gdb) n 4 return 0; (gdb) py p =3D gdb.parse_and_eval('p') (gdb) py print p @0x1001feb8: 0x10000550 (gdb) py b =3D gdb.block_for_pc(p) Traceback (most recent call last): File "", line 1, in File "/home/jwakely/gcc/gdb-10.1/share/gdb/python/gdb/__init__.py", line = 207, in block_for_pc return current_progspace().block_for_pc(pc) TypeError: must be integer, not gdb.Value Error while executing Python code. (gdb) py b =3D gdb.block_for_pc(int(p)) (gdb) py print(b) None (gdb) py b2 =3D gdb.block_for_pc(int(p.dereference().address)) (gdb) py print(b2) (gdb) py print(b2.function.name) function Using the CentOS 7 system GDB 7.6 it was worse: (gdb) start Temporary breakpoint 1 at 0x1000059c: file b.c, line 8. Starting program: /home/jwakely/tmp/a.out=20 Temporary breakpoint 1, main () at b.c:8 8 return function(1); Missing separate debuginfos, use: debuginfo-install glibc-2.17-307.el7.1.pp= c64 (gdb) step function () at b.c:3 3 int (*p)() =3D &function; (gdb) n 4 return 0; (gdb) py p =3D gdb.parse_and_eval('p') (gdb) py print(p) @0x1001feb8: 0x10000550 (gdb) py int(p) Traceback (most recent call last): File "", line 1, in gdb.error: Cannot convert value to int. Error while executing Python code. (gdb) py b =3D gdb.block_for_pc(p) Traceback (most recent call last): File "", line 1, in TypeError: must be integer, not gdb.Value Error while executing Python code. (gdb) py b =3D gdb.block_for_pc(long(p)) Traceback (most recent call last): File "", line 1, in RuntimeError: Cannot locate object file for block. Error while executing Python code. (gdb) py b =3D gdb.block_for_pc(long(p.dereference().address)) ; print b.function.name function The reason block_for_pc(long(p)) fails is that long(p) doesn't give the act= ual address of the function: (gdb) py print p @0x1001feb8: 0x10000550 (gdb) py print "0x%x" % long(p.dereference().address) 0x10000550 (gdb) py print "0x%x" % long(p) 0x1001feb8 Presumably if a gdb.Value was passed to gdb.block_for_pc it could do that automatically. --=20 You are receiving this mail because: You are on the CC list for the bug.=