llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

getopt on Windows doesn't work correctly with -- args

Open llvmbot opened this issue 11 years ago • 3 comments

Bugzilla Link 22968
Resolution INVALID
Resolved on Mar 25, 2015 17:55
Version unspecified
OS Windows NT
Reporter LLVM Bugzilla Contributor

Extended Description

Windows provides its own getopt implementation. I don't know the complete details of how getopt it supposed to work but lldb when running a command alias appears to insert a -- argument separator. For example, the "run" command is an alias for "process launch -c". When running this command, LLDB turns this argument list into "-c -- -s". When passed this way to the Windows implementation of getopt, it doesn't seem to be able to deal with the --, and can't find any arguments after this. This is also reproducible by running "process launch -- -s", in which case it won't find the -s option.

You can see this happening by putting a breakpoint inside of Args::ParseOptions, and stepping over the call to OptionParser::Parse(). It returns -1 even though it should be returning 115 (the optval for the -s option)

llvmbot avatar Mar 21 '15 02:03 llvmbot

Per discussion on lldb-dev, this appears to be working as intended.

The lldb's run alias is intended for compatibility with the gdb version.

amccarth-google avatar Mar 26 '15 00:03 amccarth-google

It seems this behavior matches the documentation for getopt:

"The special argument "--" forces an end of option-scanning regardless of the scanning mode." [http://man7.org/linux/man-pages/man3/getopt.3.html]

I'll step through your example to see if I can spot the difference in how the command is interpreted on Windows v. non-Windows.

amccarth-google avatar Mar 25 '15 20:03 amccarth-google

assigned to @amccarth-google

llvmbot avatar Mar 21 '15 02:03 llvmbot