delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2003/07/20/20:21:04

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
X-Injected-Via-Gmane: http://gmane.org/
To: cygwin AT cygwin DOT com
From: Sam Steingold <sds AT gnu DOT org>
Subject: gdb passes different argv/argc to mingw & cygwin
Date: 20 Jul 2003 20:20:47 -0400
Organization: disorganization
Lines: 92
Message-ID: <usmp03f34.fsf@gnu.org>
Reply-To: sds AT gnu DOT org
Mime-Version: 1.0
X-Complaints-To: usenet AT main DOT gmane DOT org
X-Attribution: Sam
X-Disclaimer: You should not expect anyone to agree with me.
User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50
Note-from-DJ: This may be spam

I observe some weirdness in argv/argc parsing in 1.3.22 (the current
cygwin).

Consider the attached C program and compile it with and without cygwin
like this:

$ gcc -Wall -g argtest.c -o argtest-cygwin
$ gcc -Wall -g -mno-cygwin argtest.c -o argtest-mingw

when passed arguments explicitly, they work reasonably (= like on linux)

$ ./argtest-... "4 4" '5 5'
 * argc=3
[path/argtest-...]
[4 4]
[5 5]
$

when called from a shell with the arguments in a variable, it is weird
(same weirdness as on linux, so, I guess, I need to RTFM):

arg='"4 4" '"'5 5'"
./argtest-... $arg
 * argc=5
[d:\sds\c\argtest-mingw.exe]
["4]
[4"]
['5]
[5']

(I expected the same output as with explicit args).

Now the juice: when I run these under gdb, I get _different_ output
with the same arguments:

Starting program: /cygdrive/d/sds/c/argtest-mingw.exe arg 1 2 "3" "4 4" '5 5'
 * argc=8
[d:\sds\c\argtest-mingw.exe]
[arg]
[1]
[2]
[3]
[4 4]
['5]
[5']

Starting program: /cygdrive/d/sds/c/argtest-cygwin.exe arg 1 2 "3" "4 4" '5 5'
 * argc=7
[/cygdrive/d/sds/c/argtest-cygwin]
[arg]
[1]
[2]
[3]
[4 4]
[5 5]

comments?

-- 
Sam Steingold (http://www.podval.org/~sds) running w2k
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.palestine-central.com/links.html>
Those who can't write, write manuals.


--=-=-=
Content-Type: text/c
Content-Disposition: attachment; filename=argtest.c
Content-Description: C test program

#include <stdio.h>

int main (int argc, char *argv[]) {
  printf(" * argc=%d\n",argc);
  while (argc--) printf("[%s]\n",*argv++);
  return 0;
}

--=-=-=
Content-Type: text/sh
Content-Disposition: attachment; filename=argtest
Content-Description: shell script test

#!/bin/sh
args='"4 4" '"'5 5'"
echo $args
./argtest-cygwin.exe ${args}
./argtest-mingw.exe  ${args}


--=-=-=
Content-Type: text/plain; charset=us-ascii

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/
--=-=-=--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019