Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [patch] Building simulators on windows hosts
@ 2005-04-29 14:39 Paul Brook
  2005-04-29 14:45 ` Daniel Jacobowitz
  2005-05-01  3:46 ` Eli Zaretskii
  0 siblings, 2 replies; 4+ messages in thread
From: Paul Brook @ 2005-04-29 14:39 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 760 bytes --]

The attached patch allows building the gdb simulators on windows hosts. These 
do not provide the lstat(2) or ftruncate(2) functions. truncate(2) is not 
implemented in older mingw releases.

Windows doesn't have symbolic links, so we use stat in place of lstat. For the 
missing truncate functions we just fail.

Applied to csl-arm-20050325-branch.
Ok for mainline?

Paul

2005-04-29  Paul Brook  <paul@codesourcery.com>

	* common/callback.c (PIPE_BUF): Provide default refinition.
	(os_lstat): Use stat if lstat is not available on the host.
	(os_ftruncate): Return EINVAL if not available on the host.
	(os_truncate): Ditto.
	* common/configure.ac: Check for lstat, truncate and ftruncate.
	* common/configure: Regenerate.
	* common/config.in: Regenerate.

[-- Attachment #2: patch.gdb_simhost --]
[-- Type: text/x-diff, Size: 2136 bytes --]

Index: sim/common/callback.c
===================================================================
RCS file: /var/cvsroot/src-cvs/src/sim/common/callback.c,v
retrieving revision 1.16
diff -u -p -r1.16 callback.c
--- sim/common/callback.c	21 Feb 2005 21:59:54 -0000	1.16
+++ sim/common/callback.c	28 Apr 2005 15:01:39 -0000
@@ -60,6 +60,10 @@
 #include <unistd.h>
 #endif
 
+#ifndef PIPE_BUF
+#define PIPE_BUF 512
+#endif
+
 /* ??? sim_cb_printf should be cb_printf, but until the callback support is
    broken out of the simulator directory, these are here to not require
    sim-utils.h.  */
@@ -577,7 +581,11 @@ os_lstat (p, file, buf)
      struct stat *buf;
 {
   /* NOTE: hpn/2004-12-12: Same issue here as with os_fstat.  */
+#ifdef HAVE_LSTAT
   return wrap (p, lstat (file, buf));
+#else
+  return wrap (p, stat (file, buf));
+#endif
 }
 
 static int 
@@ -596,7 +604,12 @@ os_ftruncate (p, fd, len)
     }
   if (result)
     return result;
+#ifdef HAVE_FTRUNCATE
   result = wrap (p, ftruncate (fdmap (p, fd), len));
+#else
+  p->last_errno = EINVAL;
+  result = -1;
+#endif
   return result;
 }
 
@@ -606,7 +619,12 @@ os_truncate (p, file, len)
      const char *file;
      long len;
 {
+#ifdef HAVE_TRUNCATE
   return wrap (p, truncate (file, len));
+#else
+  p->last_errno = EINVAL;
+  return -1;
+#endif
 }
 
 static int
Index: sim/common/configure.ac
===================================================================
RCS file: /var/cvsroot/src-cvs/src/sim/common/configure.ac,v
retrieving revision 1.2
diff -u -p -r1.2 configure.ac
--- sim/common/configure.ac	14 Jan 2005 20:05:40 -0000	1.2
+++ sim/common/configure.ac	28 Apr 2005 15:02:29 -0000
@@ -37,7 +37,7 @@ AC_SUBST(TARGET_SUBDIR)
 
 # These aren't all needed yet, but will be eventually.
 AC_CHECK_HEADERS(stdlib.h string.h strings.h time.h sys/times.h sys/stat.h sys/mman.h)
-AC_CHECK_FUNCS(mmap munmap)
+AC_CHECK_FUNCS(mmap munmap lstat truncate ftruncate)
 SIM_CHECK_MEMBERS([[struct stat.st_dev], [struct stat.st_ino],
 [struct stat.st_mode], [struct stat.st_nlink], [struct stat.st_uid],
 [struct stat.st_gid], [struct stat.st_rdev], [struct stat.st_size],

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [patch] Building simulators on windows hosts
  2005-04-29 14:39 [patch] Building simulators on windows hosts Paul Brook
@ 2005-04-29 14:45 ` Daniel Jacobowitz
  2005-05-01  3:46 ` Eli Zaretskii
  1 sibling, 0 replies; 4+ messages in thread
From: Daniel Jacobowitz @ 2005-04-29 14:45 UTC (permalink / raw)
  To: Paul Brook; +Cc: gdb-patches

On Fri, Apr 29, 2005 at 03:39:15PM +0100, Paul Brook wrote:
> The attached patch allows building the gdb simulators on windows hosts. These 
> do not provide the lstat(2) or ftruncate(2) functions. truncate(2) is not 
> implemented in older mingw releases.
> 
> Windows doesn't have symbolic links, so we use stat in place of lstat. For the 
> missing truncate functions we just fail.
> 
> Applied to csl-arm-20050325-branch.
> Ok for mainline?
> 
> Paul
> 
> 2005-04-29  Paul Brook  <paul@codesourcery.com>
> 
> 	* common/callback.c (PIPE_BUF): Provide default refinition.
> 	(os_lstat): Use stat if lstat is not available on the host.
> 	(os_ftruncate): Return EINVAL if not available on the host.
> 	(os_truncate): Ditto.
> 	* common/configure.ac: Check for lstat, truncate and ftruncate.
> 	* common/configure: Regenerate.
> 	* common/config.in: Regenerate.

Yes, this is OK.

-- 
Daniel Jacobowitz
CodeSourcery, LLC


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [patch] Building simulators on windows hosts
  2005-04-29 14:39 [patch] Building simulators on windows hosts Paul Brook
  2005-04-29 14:45 ` Daniel Jacobowitz
@ 2005-05-01  3:46 ` Eli Zaretskii
  2005-05-01  4:42   ` Christopher Faylor
  1 sibling, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2005-05-01  3:46 UTC (permalink / raw)
  To: Paul Brook; +Cc: gdb-patches

> From: Paul Brook <paul@codesourcery.com>
> Date: Fri, 29 Apr 2005 15:39:15 +0100
> 
> +#ifdef HAVE_LSTAT
>    return wrap (p, lstat (file, buf));
> +#else
> +  return wrap (p, stat (file, buf));
> +#endif

Wouldn't it be cleaner to say in some strategic place (like a header
included by many sim files)

 #ifndef HAVE_LSTAT
 #define lstat stat
 #endif

and then leave the *.c files alone?  I think this is a better
solution, and include/gdb/callback.h seems like a good place to do
that.

Perhaps it's even something MinGW headers should do for you, but for
now a GDB solution will be fine.

> +#ifdef HAVE_FTRUNCATE
>    result = wrap (p, ftruncate (fdmap (p, fd), len));
> +#else
> +  p->last_errno = EINVAL;
> +  result = -1;
> +#endif
>    return result;

`ftruncate' is a very simple function; you could write an emulation
using `lseek' and `write'.  (If you want, I can show you the
implementation from the DJGPP library.)  I think it's better to add
such an emulation that to fail the calls.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [patch] Building simulators on windows hosts
  2005-05-01  3:46 ` Eli Zaretskii
@ 2005-05-01  4:42   ` Christopher Faylor
  0 siblings, 0 replies; 4+ messages in thread
From: Christopher Faylor @ 2005-05-01  4:42 UTC (permalink / raw)
  To: gdb-patches, Paul Brook, Eli Zaretskii

On Sun, May 01, 2005 at 06:42:10AM +0300, Eli Zaretskii wrote:
>> From: Paul Brook <paul@codesourcery.com>
>> Date: Fri, 29 Apr 2005 15:39:15 +0100
>> 
>> +#ifdef HAVE_LSTAT
>>    return wrap (p, lstat (file, buf));
>> +#else
>> +  return wrap (p, stat (file, buf));
>> +#endif
>
>Wouldn't it be cleaner to say in some strategic place (like a header
>included by many sim files)
>
> #ifndef HAVE_LSTAT
> #define lstat stat
> #endif
>
>and then leave the *.c files alone?  I think this is a better
>solution, and include/gdb/callback.h seems like a good place to do
>that.
>
>Perhaps it's even something MinGW headers should do for you, but for
>now a GDB solution will be fine.

I agree with the above.  Sprinkling ifdefs for things like this in the
code is really not pretty.

>> +#ifdef HAVE_FTRUNCATE
>>    result = wrap (p, ftruncate (fdmap (p, fd), len));
>> +#else
>> +  p->last_errno = EINVAL;
>> +  result = -1;
>> +#endif
>>    return result;
>
>`ftruncate' is a very simple function; you could write an emulation
>using `lseek' and `write'.  (If you want, I can show you the
>implementation from the DJGPP library.)  I think it's better to add
>such an emulation that to fail the calls.

FWIW, the windows equivalent of 'ftruncate' is more-or-less 'SetEndOfFile'.

It should be pretty easy to write an emulation of ftruncate using that.

cgf


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-05-01  4:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-29 14:39 [patch] Building simulators on windows hosts Paul Brook
2005-04-29 14:45 ` Daniel Jacobowitz
2005-05-01  3:46 ` Eli Zaretskii
2005-05-01  4:42   ` Christopher Faylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox