Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [RFA] Fix scm-ports.exp regression
Date: Mon, 15 Jan 2018 16:51:00 -0000	[thread overview]
Message-ID: <d52d9a5d-75d1-a71f-0ecb-021053e6cdd5@redhat.com> (raw)
In-Reply-To: <87efmykhw1.fsf@tromey.com>

Hi Tromey,

Sorry for the delay.
On 01/09/2018 06:26 PM, Tom Tromey wrote:
>>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
> 
>>> I think the simplest fix is to use "print/u" rather than "print/d" to
>>> get the value of sp_reg in the test case.
> 
> Pedro> Can you expand a bit on this rationale, please?
> 
> Pedro> There's:
> Pedro>  (parse-and-eval \"*(char*) \$sp\")
> Pedro> in the context of the diff.  Is that related?  I ask because
> Pedro> that "char" in there would look like something that could print
> Pedro> as signed or unsigned depending on target.
> 
> I don't think that is related.  That expression has a dereference.
> 
> What happens is that on x86, this:
> 
> 	set sp_reg [get_integer_valueof "\$sp" 0]
> 
> ... ends up setting sp_reg to a negative value, because
> get_integer_valueof uses "print/d":
> 
>     print /d $sp
>     $1 = -11496
> 
> Then later the test suite does:
> 
> 	gdb_test "guile (print (seek rw-mem-port (value->integer sp-reg) SEEK_SET))" \
> 	    "= $sp_reg" \
> 	    "seek to \$sp"
> 
> ... expecting this value to be identical to the saved $sp_reg value.
> However it gets:
> 
>     guile (print (seek rw-mem-port (value->integer sp-reg) SEEK_SET))
>     = 4294955800
> 
> "print" is just a wrapper for guile's format:
> 
>     gdb_test_no_output "guile (define (print x) (format #t \"= ~A\" x) (newline))"
> 
> The seek function returns a scm_t_off, so I would think that this sort
> of printing is handled by guile, not by gdb.

I see.  So seemingly this is printing a scm_t_off, which seems to be a
signed 64-bit integer:

 /usr/include/guile/2.0/libguile/scmconfig-32.h:82:typedef int64_t scm_t_int64;
 /usr/include/guile/2.0/libguile/scmconfig-32.h:119:typedef scm_t_int64 scm_t_off;
 /usr/include/guile/2.0/libguile/scmconfig-64.h:82:typedef int64_t scm_t_int64;
 /usr/include/guile/2.0/libguile/scmconfig-64.h:119:typedef scm_t_int64 scm_t_off;

while $sp is 32-bit, and we're extracting it as a 32-bit signed
integer (into $sp_reg).

Here:

  (seek rw-mem-port (value->integer sp-reg) SEEK_SET)

"sp-reg" is a pointer, and value->integer takes us to
gdbscm_value_to_integer [I think], which converts the pointer to
an unsigned integer, AFAICT, and then probably that gets cast/converted to
scm_t_off when passed to guile's "seek", somewhere.  And then
'seek' returns the same offset out, as an scm_t_off, and then guile's
'format' prints that.

So pedantically, doing:

"print (scm_t_off) $sp"

   (or really "print (int64_t) $sp",
    or even   "print (long long) $sp"...)

to extract $sp_reg would be a little more to the point, I guess.

But it looks like on 64-bit archs, the API can't access memory
addresses with the high bit set anyway (?) (not sure how to get
those; maybe debugging some bare metal/kernel code), so the
difference doesn't really matter much in practice.

The patch is fine with me as is.  I just wish the commit
log were a little clearer with details such as the above.

> IIRC what happened is that "print/d" slightly changed in some cases
> during the scalar printing work, and what we're seeing is the result.
Yes, before the rework, "/d" would still print integers
as unsigned in some cases.  Now it always prints them as signed,
as if it you wrote something like this:

  (gdb) print (std::make_signed<decltype(EXPR)>::type) EXPR

instead of:

  (gdb) print /d EXPR

with the difference that /d affects display only,
unlike a cast which affects the actual value recorded in
the value history.

Thanks,
Pedro Alves


  reply	other threads:[~2018-01-15 16:51 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-03 18:20 Tom Tromey
2018-01-05 17:01 ` Pedro Alves
2018-01-09 18:27   ` Tom Tromey
2018-01-15 16:51     ` Pedro Alves [this message]
2018-01-15 18:17       ` Tom Tromey
2018-01-15 20:59         ` Sergio Durigan Junior
2018-01-15 22:10           ` Tom Tromey
2018-01-16  7:39             ` Joel Brobecker
2018-01-05 17:59 Doug Evans via gdb-patches

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=d52d9a5d-75d1-a71f-0ecb-021053e6cdd5@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.com \
    /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