* How to use control-D character?
@ 2010-10-12 10:51 ali hagigat
2010-10-12 13:17 ` Ian Lance Taylor
0 siblings, 1 reply; 6+ messages in thread
From: ali hagigat @ 2010-10-12 10:51 UTC (permalink / raw)
To: binutils; +Cc: bug-binutils
My question is about as, GNU assembler, Version 2.14 and I have copied
the related extract from the manual:
-----------------------------------------
1.5 Input Files
If you give 'as' no file names it attempts to read one input file from
the as standard input,
which is normally your terminal. You may have to type ctl-D to tell as
there is no more
program to assemble.
----------------------------------------
How can i use <ctl-D> key combination? Will it be typed at the end of
'as' command line?
When i type:
as <ctl-D>
'as' will wait for user to enter some lines of instruction!!
If I use 'as' alone and then enter some assembly lines , how can i
terminate the input terminal text and make 'as' assemble the lines I
have written?
Thank you to read my message.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to use control-D character?
2010-10-12 10:51 How to use control-D character? ali hagigat
@ 2010-10-12 13:17 ` Ian Lance Taylor
2010-10-13 6:54 ` ali hagigat
0 siblings, 1 reply; 6+ messages in thread
From: Ian Lance Taylor @ 2010-10-12 13:17 UTC (permalink / raw)
To: ali hagigat; +Cc: binutils, bug-binutils
ali hagigat <hagigatali@gmail.com> writes:
> My question is about as, GNU assembler, Version 2.14 and I have copied
> the related extract from the manual:
> -----------------------------------------
> 1.5 Input Files
> If you give 'as' no file names it attempts to read one input file from
> the as standard input,
> which is normally your terminal. You may have to type ctl-D to tell as
> there is no more
> program to assemble.
> ----------------------------------------
>
> How can i use <ctl-D> key combination? Will it be typed at the end of
> 'as' command line?
> When i type:
> as <ctl-D>
> 'as' will wait for user to enter some lines of instruction!!
>
> If I use 'as' alone and then enter some assembly lines , how can i
> terminate the input terminal text and make 'as' assemble the lines I
> have written?
http://en.wikipedia.org/wiki/End-of-file
In other words, type
as
your input file
^D
This assumes that you are using Unix or GNU/Linux; you didn't say.
Ian
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to use control-D character?
2010-10-12 13:17 ` Ian Lance Taylor
@ 2010-10-13 6:54 ` ali hagigat
2010-10-13 13:13 ` Ian Lance Taylor
0 siblings, 1 reply; 6+ messages in thread
From: ali hagigat @ 2010-10-13 6:54 UTC (permalink / raw)
To: binutils, bug-binutils
Thank you to reply to my message. Ian, I am using Linux, Fedora 12.
I typed 'as' as you wrote:
root> as
Then I wrote the name of my input file:
root> asm1.s
Then i pressed <ENTER> and then <ctl-D> and nothing happned!
For the second time I pressed <ctl-D> and now I have the following
error message:
{standard input}: Assembler messages:
{standard input}:1: Error: no such instruction: `asm1.s'
I think you meant writing some assembly instructions before <CTL-D>.
But when I type:
root> as <ENTER>
root> mov $0, %eax <ENTER>
root> <CAPS LOCK> <CTL-D>
nothing happens!! but if i press <CTL-D> for two more times, it will
exit from as and returns back to my shell prompt!
So what happened? Did it assemble the line? Why this <CTL-D> is
useful, how it is used?
Thank you to read my message.
On Tue, Oct 12, 2010 at 4:47 PM, Ian Lance Taylor <ian@airs.com> wrote:
> http://en.wikipedia.org/wiki/End-of-file
>
> In other words, type
>
> as
> your input file
> ^D
>
> This assumes that you are using Unix or GNU/Linux; you didn't say.
>
> Ian
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to use control-D character?
2010-10-13 6:54 ` ali hagigat
@ 2010-10-13 13:13 ` Ian Lance Taylor
2010-10-16 20:14 ` Maciej W. Rozycki
0 siblings, 1 reply; 6+ messages in thread
From: Ian Lance Taylor @ 2010-10-13 13:13 UTC (permalink / raw)
To: ali hagigat; +Cc: binutils, bug-binutils
ali hagigat <hagigatali@gmail.com> writes:
> Thank you to reply to my message. Ian, I am using Linux, Fedora 12.
> I typed 'as' as you wrote:
> root> as
> Then I wrote the name of my input file:
> root> asm1.s
> Then i pressed <ENTER> and then <ctl-D> and nothing happned!
> For the second time I pressed <ctl-D> and now I have the following
> error message:
> {standard input}: Assembler messages:
> {standard input}:1: Error: no such instruction: `asm1.s'
>
> I think you meant writing some assembly instructions before <CTL-D>.
> But when I type:
> root> as <ENTER>
> root> mov $0, %eax <ENTER>
> root> <CAPS LOCK> <CTL-D>
> nothing happens!! but if i press <CTL-D> for two more times, it will
> exit from as and returns back to my shell prompt!
> So what happened? Did it assemble the line? Why this <CTL-D> is
> useful, how it is used?
As noted in http://en.wikipedia.org/wiki/End-of-file , ^D is the
standard Unix end-of-file indicator from the terminal. You don't need
to use the caps lock or the shift key; pressing the control key and the
D key simultaneously is sufficient.
The fact that you have to type ^D more than once seems like a bug in the
GNU assembler. Please consider reporting it at
http://sourceware.org/bugzilla/ .
And, yes, when you do type it more than once, and the assembler exits,
then it has assembled the line you typed. You will find the results in
the file "a.out".
Ian
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to use control-D character?
2010-10-13 13:13 ` Ian Lance Taylor
@ 2010-10-16 20:14 ` Maciej W. Rozycki
2010-10-27 14:06 ` Nick Clifton
0 siblings, 1 reply; 6+ messages in thread
From: Maciej W. Rozycki @ 2010-10-16 20:14 UTC (permalink / raw)
To: Ian Lance Taylor; +Cc: ali hagigat, binutils, bug-binutils
On Wed, 13 Oct 2010, Ian Lance Taylor wrote:
> The fact that you have to type ^D more than once seems like a bug in the
> GNU assembler. Please consider reporting it at
> http://sourceware.org/bugzilla/ .
We have two problems on Linux apparently:
1. input_file_open() uses ungetc(3) without checking for EOF.
2. glibc does not handle the EOF condition in the context of ungetc(3)
correctly when input is connected to the terminal.
The issue #1 above is obvious and only applies to EOF seen right at the
beginning. I'll elaborate on #2. We make this sequence of calls on
input:
getc()
ungetc()
fread()
fread()
fread()
...
The call to getc(3) collects a line of input with read(2) (that is
retained) and returns the first character. The call to ungetc(3) pushes
the character back to the head of the line. The call to fread(3) collects
another line of input (that is retained) with read(2) and returns the line
previously collected by getc(3). The next call to fread(3) collects
another line of input (that is retained) with read(2) and returns the line
collected by the previous call to fread(3), etc., etc...
Now if at any point read(2) returns EOF, then glibc records the fact (see
libio/fileops.c and look for "fp->_flags |= _IO_EOF_SEEN" assignments,
such as in _IO_file_xsgetn() that is used by fread(3)), but obviously it
still has to return the line buffered by the previous call to fread(3).
The EOF condition is expected to be triggered by the next call to fread(3)
(or, to be exact, once all the buffered characters have been consumed, up
to which point fread(3) should refrain from making further calls to
read(2)), but that doesn't happen unless the associated read(2) call
returns another EOF, because glibc actually never checks whether the
_IO_EOF_SEEN flag is set.
The ISO C99 standard seems a bit imprecise about the interaction between
ungetc(3) and fread(3), which matters especially in the context of
line-mode devices such as terminals. The above is my interpretation of
how these calls should behave only, that is guaranteed the glibc
maintainers will disagree with, as usually.
Fixing input_file_open() looks moderately easy, although will only
address a corner case. Frankly I find the way #NO_APP is handled in
input_file_open() rather hackish.
Fixing glibc is the actual problem, but strictly speaking outside the
scope of binutils, although we may recognise some interest. Perhaps the
best choice would simply be avoiding the grey area and rewriting the
handling of #NO_APP in a more civilised way.
Maciej
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: How to use control-D character?
2010-10-16 20:14 ` Maciej W. Rozycki
@ 2010-10-27 14:06 ` Nick Clifton
0 siblings, 0 replies; 6+ messages in thread
From: Nick Clifton @ 2010-10-27 14:06 UTC (permalink / raw)
To: Maciej W. Rozycki; +Cc: Ian Lance Taylor, ali hagigat, binutils, bug-binutils
[-- Attachment #1: Type: text/plain, Size: 2325 bytes --]
Hi Maciej,
> 1. input_file_open() uses ungetc(3) without checking for EOF.
>
> 2. glibc does not handle the EOF condition in the context of ungetc(3)
> correctly when input is connected to the terminal.
>
> The issue #1 above is obvious and only applies to EOF seen right at the
> beginning. I'll elaborate on #2. We make this sequence of calls on
> input:
>
> getc()
> ungetc()
> fread()
> fread()
> fread()
> ...
>
> The call to getc(3) collects a line of input with read(2) (that is
> retained) and returns the first character. The call to ungetc(3) pushes
> the character back to the head of the line. The call to fread(3) collects
> another line of input (that is retained) with read(2) and returns the line
> previously collected by getc(3). The next call to fread(3) collects
> another line of input (that is retained) with read(2) and returns the line
> collected by the previous call to fread(3), etc., etc...
>
> Now if at any point read(2) returns EOF, then glibc records the fact (see
> libio/fileops.c and look for "fp->_flags |= _IO_EOF_SEEN" assignments,
> such as in _IO_file_xsgetn() that is used by fread(3)), but obviously it
> still has to return the line buffered by the previous call to fread(3).
> The EOF condition is expected to be triggered by the next call to fread(3)
> (or, to be exact, once all the buffered characters have been consumed, up
> to which point fread(3) should refrain from making further calls to
> read(2)), but that doesn't happen unless the associated read(2) call
> returns another EOF, because glibc actually never checks whether the
> _IO_EOF_SEEN flag is set.
>
> The ISO C99 standard seems a bit imprecise about the interaction between
> ungetc(3) and fread(3), which matters especially in the context of
> line-mode devices such as terminals. The above is my interpretation of
> how these calls should behave only, that is guaranteed the glibc
> maintainers will disagree with, as usual.
Imagining that I am Uli for a second, it occurs to me that he will
defend glibc by saying that we ought to be calling feof() to check for
the end of file condition before calling fread().
So what do you think of this patch, which appears to take care of both
points (1) and (2), although it does not attempt to tidy up the #NO_APP
processing ?
Cheers
Nick
[-- Attachment #2: input-file.c.patch --]
[-- Type: text/x-diff, Size: 1254 bytes --]
Index: gas/input-file.c
===================================================================
RCS file: /cvs/src/src/gas/input-file.c,v
retrieving revision 1.27
diff -u -3 -p -r1.27 input-file.c
--- gas/input-file.c 2 Sep 2009 07:24:19 -0000 1.27
+++ gas/input-file.c 27 Oct 2010 14:02:11 -0000
@@ -157,6 +157,15 @@ input_file_open (char *filename, /* "" m
return;
}
+ /* Check for an empty input file. */
+ if (feof (f_in))
+ {
+ fclose (f_in);
+ f_in = NULL;
+ return;
+ }
+ gas_assert (c != EOF);
+
if (c == '#')
{
/* Begins with comment, may not want to preprocess. */
@@ -209,6 +218,9 @@ input_file_get (char *buf, int buflen)
{
int size;
+ if (feof (f_in))
+ return 0;
+
size = fread (buf, sizeof (char), buflen, f_in);
if (size < 0)
{
@@ -235,7 +247,13 @@ input_file_give_next_buffer (char *where
if (preprocess)
size = do_scrub_chars (input_file_get, where, BUFFER_SIZE);
else
- size = fread (where, sizeof (char), BUFFER_SIZE, f_in);
+ {
+ if (feof (f_in))
+ size = 0;
+ else
+ size = fread (where, sizeof (char), BUFFER_SIZE, f_in);
+ }
+
if (size < 0)
{
as_bad (_("can't read from %s: %s"), file_name, xstrerror (errno));
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2010-10-27 14:06 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-12 10:51 How to use control-D character? ali hagigat
2010-10-12 13:17 ` Ian Lance Taylor
2010-10-13 6:54 ` ali hagigat
2010-10-13 13:13 ` Ian Lance Taylor
2010-10-16 20:14 ` Maciej W. Rozycki
2010-10-27 14:06 ` Nick Clifton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).