public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "jwakely.gcc at gmail dot com" <sourceware-bugzilla@sourceware.org>
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 [thread overview]
Message-ID: <bug-27000-4717-vQTuDFA2F2@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-27000-4717@http.sourceware.org/bugzilla/>
https://sourceware.org/bugzilla/show_bug.cgi?id=27000
--- Comment #1 from Jonathan Wakely <jwakely.gcc at gmail dot com> ---
(In reply to Jonathan Wakely from comment #0)
> - Calling int with gdb.Value should not raise an exception if long(v) would
> work instead, just do that.
>
> - 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)() = &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
Temporary breakpoint 2, main () at b.c:8
8 return function(1);
(gdb) step
function () at b.c:3
3 int (*p)() = &function;
(gdb) n
4 return 0;
(gdb) py p = gdb.parse_and_eval('p')
(gdb) py print p
@0x1001feb8: 0x10000550 <function>
(gdb) py b = gdb.block_for_pc(p)
Traceback (most recent call last):
File "<string>", line 1, in <module>
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<K>, not gdb.Value
Error while executing Python code.
(gdb) py b = gdb.block_for_pc(int(p))
(gdb) py print(b)
None
(gdb) py b2 = gdb.block_for_pc(int(p.dereference().address))
(gdb) py print(b2)
<gdb.Block object at 0x3fff9d797db0>
(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
Temporary breakpoint 1, main () at b.c:8
8 return function(1);
Missing separate debuginfos, use: debuginfo-install glibc-2.17-307.el7.1.ppc64
(gdb) step
function () at b.c:3
3 int (*p)() = &function;
(gdb) n
4 return 0;
(gdb) py p = gdb.parse_and_eval('p')
(gdb) py print(p)
@0x1001feb8: 0x10000550 <function>
(gdb) py int(p)
Traceback (most recent call last):
File "<string>", line 1, in <module>
gdb.error: Cannot convert value to int.
Error while executing Python code.
(gdb) py b = gdb.block_for_pc(p)
Traceback (most recent call last):
File "<string>", line 1, in <module>
TypeError: must be integer<K>, not gdb.Value
Error while executing Python code.
(gdb) py b = gdb.block_for_pc(long(p))
Traceback (most recent call last):
File "<string>", line 1, in <module>
RuntimeError: Cannot locate object file for block.
Error while executing Python code.
(gdb) py b = 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 actual
address of the function:
(gdb) py print p
@0x1001feb8: 0x10000550 <function>
(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.
--
You are receiving this mail because:
You are on the CC list for the bug.
next prev parent reply other threads:[~2020-12-02 21:18 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-02 21:03 [Bug python/27000] New: " jwakely.gcc at gmail dot com
2020-12-02 21:18 ` jwakely.gcc at gmail dot com [this message]
2020-12-02 21:24 ` [Bug python/27000] " tromey at sourceware dot org
2022-06-04 16:59 ` tromey at sourceware dot org
2022-06-05 13:42 ` tromey at sourceware dot org
2022-07-08 20:28 ` cvs-commit at gcc dot gnu.org
2022-07-08 20:29 ` tromey at sourceware dot org
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bug-27000-4717-vQTuDFA2F2@http.sourceware.org/bugzilla/ \
--to=sourceware-bugzilla@sourceware.org \
--cc=gdb-prs@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).