Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: ppluzhnikov@google.com (Paul Pluzhnikov)
To: gdb-patches@sourceware.org
Subject: [patch] Fix a glitch in debugging 32-bit process with 64-bit GDB.
Date: Tue, 09 Dec 2008 01:33:00 -0000	[thread overview]
Message-ID: <20081209013252.9E1C83A6B2E@localhost> (raw)

Greetings,

This came up while debugging one of my core files.
The symptom is:

GNU gdb (GDB) 6.8.50.20081209-cvs
...
This GDB was configured as "x86_64-unknown-linux-gnu".
...
Core was generated by `/tmp/a.out'.
Program terminated with signal 11, Segmentation fault.
[New process 7763]
[New process 13974]
[New process 7773]
#0  chunk_alloc (ar_ptr=Cannot access memory at address 0xffffbf88      <<< What's that?
) at malloc.c:2896
2896    malloc.c: No such file or directory.
       in malloc.c
(gdb) p ar_ptr
Cannot access memory at address 0xffffbf88

32-bit gdb doesn't have a problem on the same core:

Program terminated with signal 11, Segmentation fault.
[New process 7763]
[New process 13974]
[New process 7773]
#0  chunk_alloc (ar_ptr=0x1184f00, nb=10249) at malloc.c:2896

The problem is that in findvar.c:

    case LOC_ARG:
      if (frame == NULL)
	return 0;
      addr = get_frame_args_address (frame);
      if (!addr)
	return 0;
      addr += SYMBOL_VALUE (var);
      break;

What happens if sizeof(addr) == 8 (64-bit gdb), len == 4 (32-bit target),
get_frame_args_address() returns 0xffffbf98 (typical stack address)
and SYMBOL_VALUE() returns -16? 

We end up with an impossible target address of 0x1ffffbf88.

Attached patch fixes this.
OK?

--
Paul Pluzhnikov

2008-12-08  Paul Pluzhnikov  <ppluzhnikov@google.com>

	* findvar.c (read_var_value): Truncate addr to target len.
	

Index: findvar.c
===================================================================
RCS file: /cvs/src/src/gdb/findvar.c,v
retrieving revision 1.119
diff -u -p -u -r1.119 findvar.c
--- findvar.c	2 Dec 2008 14:51:00 -0000	1.119
+++ findvar.c	9 Dec 2008 01:32:10 -0000
@@ -565,6 +565,10 @@ read_var_value (struct symbol *var, stru
       break;
     }
 
+  if (sizeof (addr) > len)
+    /* Truncate address to target length.  */
+    addr &= (1L << (8 * len)) - 1;
+
   VALUE_ADDRESS (v) = addr;
   set_value_lazy (v, 1);
   return v;


             reply	other threads:[~2008-12-09  1:33 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-12-09  1:33 Paul Pluzhnikov [this message]
2008-12-09  2:08 ` Daniel Jacobowitz
2008-12-09  2:43   ` Paul Pluzhnikov
2008-12-09 11:30     ` Peter Schauer
2008-12-09 13:34     ` Daniel Jacobowitz
2008-12-10 11:14       ` Joel Brobecker
2008-12-10 15:59         ` Paul Pluzhnikov
2008-12-10 23:21           ` Paul Pluzhnikov
2008-12-11  8:57             ` Andreas Schwab
     [not found]               ` <8ac60eac0812111601v20566268h6f7977c71e5b8a8f@mail.gmail.com>
2008-12-12  0:11                 ` Paul Pluzhnikov
2008-12-13 16:02                   ` Joel Brobecker
2008-12-13 18:18                     ` Paul Pluzhnikov
2008-12-15  8:59                       ` Joel Brobecker
2008-12-15 21:47                         ` Paul Pluzhnikov
2008-12-16  4:48                           ` Joel Brobecker
2008-12-11  9:21             ` Mark Kettenis

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=20081209013252.9E1C83A6B2E@localhost \
    --to=ppluzhnikov@google.com \
    --cc=gdb-patches@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