Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Mike Frysinger <vapier@gentoo.org>
To: gdb-patches@sourceware.org
Cc: toolchain-devel@blackfin.uclinux.org
Subject: [PATCH v2] sim: allow memory maps to default to mapped files
Date: Thu, 30 Dec 2010 21:09:00 -0000	[thread overview]
Message-ID: <1293741562-9225-1-git-send-email-vapier@gentoo.org> (raw)
In-Reply-To: <1293426471-5571-1-git-send-email-vapier@gentoo.org>

I find it annoying when using --memory-mapfile that I also need to look
up and manually specify the file size to the following --memory-region
option.  So make a length of 0 in the following --memory-region trigger
an auto-sizing of the map to the length of the file being mapped.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

2010-12-27  Mike Frysinger  <vapier@gentoo.org>

	* sim-memopt.c (do_memopt_add): Set nr_bytes to s.st_size before
	bytes has been calculated and when mmap_next_fd is valid and
	nr_bytes is 0.
	(memory_option_handler): Allow missing size when mmap_next_fd is
	valid.
---
v2
	- fix typo in nr_bytes==0 handling

 sim/common/sim-memopt.c |   40 ++++++++++++++++++++++++++++++----------
 1 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/sim/common/sim-memopt.c b/sim/common/sim-memopt.c
index 99e6add..5ef48cb 100644
--- a/sim/common/sim-memopt.c
+++ b/sim/common/sim-memopt.c
@@ -154,7 +154,27 @@ do_memopt_add (SIM_DESC sd,
       /* Allocate new well-aligned buffer, just as sim_core_attach(). */
       void *aligned_buffer;
       int padding = (addr % sizeof (unsigned64));
-      unsigned long bytes = (modulo == 0 ? nr_bytes : modulo) + padding;
+      unsigned long bytes;
+
+#ifdef HAVE_MMAP
+      struct stat s;
+
+      if (mmap_next_fd >= 0)
+	{
+	  /* Check that given file is big enough. */
+	  int rc = fstat (mmap_next_fd, &s);
+
+	  if (rc < 0)
+	    sim_io_error (sd, "Error, unable to stat file: %s\n",
+			  strerror (errno));
+
+	  /* Autosize the mapping to the file length.  */
+	  if (nr_bytes == 0)
+	    nr_bytes = s.st_size;
+	}
+#endif
+
+      bytes = (modulo == 0 ? nr_bytes : modulo) + padding;
 
       free_buffer = NULL;
       free_length = bytes;
@@ -163,14 +183,9 @@ do_memopt_add (SIM_DESC sd,
       /* Memory map or malloc(). */
       if (mmap_next_fd >= 0)
 	{
-	  /* Check that given file is big enough. */
-	  struct stat s;
-	  int rc;
-
 	  /* Some kernels will SIGBUS the application if mmap'd file
 	     is not large enough.  */ 
-	  rc = fstat (mmap_next_fd, &s);
-	  if (rc < 0 || s.st_size < bytes)
+	  if (s.st_size < bytes)
 	    {
 	      sim_io_error (sd,
 			    "Error, cannot confirm that mmap file is large enough "
@@ -383,10 +398,15 @@ memory_option_handler (SIM_DESC sd, sim_cpu *cpu, int opt,
 	chp = parse_addr (chp, &level, &space, &addr);
 	if (*chp != ',')
 	  {
-	    sim_io_eprintf (sd, "Missing size for memory-region\n");
-	    return SIM_RC_FAIL;
+	    /* let the file autosize */
+	    if (mmap_next_fd == -1)
+	      {
+		sim_io_eprintf (sd, "Missing size for memory-region\n");
+		return SIM_RC_FAIL;
+	      }
 	  }
-	chp = parse_size (chp + 1, &nr_bytes, &modulo);
+	else
+	  chp = parse_size (chp + 1, &nr_bytes, &modulo);
 	/* old style */
 	if (*chp == ',')
 	  modulo = strtoul (chp + 1, &chp, 0);
-- 
1.7.3.1


  parent reply	other threads:[~2010-12-30 20:40 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-27 13:10 [PATCH] " Mike Frysinger
2010-12-28  7:38 ` Joel Brobecker
2010-12-28  7:39   ` Joel Brobecker
2010-12-28  8:02     ` Mike Frysinger
2010-12-28  7:46   ` Mike Frysinger
2010-12-28 11:00     ` Joel Brobecker
2010-12-28 14:34     ` Joel Brobecker
2010-12-28 23:17       ` Eli Zaretskii
2011-01-09  3:39       ` Mike Frysinger
2011-01-11 15:07         ` Doug Evans
2011-01-11 16:04           ` [toolchain-devel] " Mike Frysinger
2011-01-11 17:02             ` Doug Evans
2011-01-11 17:06               ` Doug Evans
2010-12-28 19:16     ` Eli Zaretskii
2010-12-29  1:52     ` Michael Snyder
2010-12-30 21:09 ` Mike Frysinger [this message]
2011-01-11 19:05 ` Mike Frysinger

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=1293741562-9225-1-git-send-email-vapier@gentoo.org \
    --to=vapier@gentoo.org \
    --cc=gdb-patches@sourceware.org \
    --cc=toolchain-devel@blackfin.uclinux.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