Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » CDT Debug not reading EOF from console(Under debug, the CDT console don't get the EOF (ctrl-D) )
CDT Debug not reading EOF from console [message #1850159] Fri, 18 February 2022 11:50 Go to next message
Giuliano Lotta is currently offline Giuliano LottaFriend
Messages: 9
Registered: June 2016
Junior Member
Hi all!
Using Eclipse 2021.09 + CDT 10.5 + Ubuntu 20.04

when in debug of a CLI program, I cannot send any EOF (ctrl+D) to the program by the console.
Iit seems the the options "Connect process input & output to a terminal" that was proposed to fix the bugs many years ago, is NO MORE available in the config menu of Eclipse/CDT (is it?) ...
so I cannot found any workaround ...

Reading with a read() and getchar() completely IGNORE the ctrl-D...

KINDLY ask:

Are you facing the same problems during debug in CDT ?
Is there a workaround for my configuration, to send and EOF to the console during debug operations ?

Here an example Both reading with getchar and read DO return only after pressing enter, BUT if I press ctrl-D, the trace debug is lost, and the control never returns to the debug window, even i I enter Enter after having pressed ctrl-D... Seems that ctrl-D on the console terminal gets the console stucked ...

        int position = 0; // writing buffer position 
	int ch;
	ch = getchar();
	//ch = read(STDIN_FILENO,&ch,1);
	while (ch != EOF) {
		(*buffer)[position] = (char) ch;
		position++;
		//printf("ch = %d\n", ch);
		if (buf_len == position) { // buffer full ? double size!
			buf_len *= 2;
			*buffer = realloc(*buffer, buf_len);
			if (buffer == NULL) {
				perror("malloc()");
				exit(EXIT_FAILURE);
			}
		}
		//ch = read(STDIN_FILENO,&ch,1);
		ch = read(STDIN_FILENO, &ch, sizeof(ch));
	}
	return position;


BR
Giuliano

[Updated on: Sat, 19 February 2022 09:28]

Report message to a moderator

Re: CDT Debug not reading EOF from console [message #1850162 is a reply to message #1850159] Fri, 18 February 2022 14:53 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
How are you testing for EOF after the read?

Does your code look like this ?
https://stackoverflow.com/a/30304749/3312726

[Updated on: Fri, 18 February 2022 14:57]

Report message to a moderator

Re: CDT Debug not reading EOF from console [message #1850172 is a reply to message #1850162] Sat, 19 February 2022 09:33 Go to previous messageGo to next message
Giuliano Lotta is currently offline Giuliano LottaFriend
Messages: 9
Registered: June 2016
Junior Member
Thanks for your reply
I checked and and both the functions getchar() and read() (sorry, I mispelled scanf in the first message... edited)
Both getchar() and read() do NOT return if I press ctrl-d .. ever worst the both do return if I press Enter, but both do NOR return if I press ctrl-D, and the consolle do not get back the control to the debug windows, even if I _then_ press Enter....

Here an example:

        int position = 0; // writing buffer position 
	int ch;
	ch = getchar();
	//ch = read(STDIN_FILENO,&ch,1);
	while (ch != EOF) {
		(*buffer)[position] = (char) ch;
		position++;
		//printf("ch = %d\n", ch);
		if (buf_len == position) { // buffer full ? double size!
			buf_len *= 2;
			*buffer = realloc(*buffer, buf_len);
			if (buffer == NULL) {
				perror("malloc()");
				exit(EXIT_FAILURE);
			}
		}
		//ch = read(STDIN_FILENO,&ch,1);
		ch = read(STDIN_FILENO, &ch, sizeof(ch));
	}
	return position;
Re: CDT Debug not reading EOF from console [message #1850173 is a reply to message #1850172] Sat, 19 February 2022 10:33 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
You should read the manual.
It would have saved a lot of time.

This is off topic for this forum which isn't for
fixing programming problems.

read returns zero at eof and -1 on error.
getchar returns the character read as an
unsigned char int or EOF on end of file or error.

"read(2) - Linux manual page"
https://man7.org/linux/man-pages/man2/read.2.html
https://www.cplusplus.com/reference/cstdio/getchar/

UPDATE:
Don't use the edit function to completely rewrite your posts.
Any answers won't make sense to anyone who doesn't know
the original content.

[Updated on: Sat, 19 February 2022 10:43]

Report message to a moderator

Re: CDT Debug not reading EOF from console [message #1850174 is a reply to message #1850173] Sat, 19 February 2022 11:15 Go to previous messageGo to next message
Giuliano Lotta is currently offline Giuliano LottaFriend
Messages: 9
Registered: June 2016
Junior Member
Thanks for your reply,
but perhaps i did not highlighted well the meaningful part of the problem wit CDT

Your answer is about what read(()/getchar() are returning BUT the problem is that during debug the CONSOLE DOES NOT RETURN after having pressed [Ctrl+D]+ [Enter] in the CDT debug console, when getchar() or read() are used.

The problem is not what the function are returning.. they are simply NOT RETURNING if I have pressed [Enter], after having pressed Ctrl+D.
Try yourself an your will see that pressing [ctrld+D] +[Enter] inside the console during a getchar() or read() GET STUCK the console and the debugger...
You cannot get back to trace the program again !!

of course, the read() and getchar(), must wait for the [Enter] return the value to the program,
BUT the problem is that when I press ctrl-D and then Enter in the CDT debug console, they DO NOT return...
And this seem a clear BUG in the console...
Re: CDT Debug not reading EOF from console [message #1850175 is a reply to message #1850174] Sat, 19 February 2022 11:44 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
Why do you think it's a problem with Eclipse?
The code you gave won't work.
Have you tried running it outside of Eclipse?
Re: CDT Debug not reading EOF from console [message #1850176 is a reply to message #1850175] Sat, 19 February 2022 14:28 Go to previous messageGo to next message
David Wegener is currently offline David WegenerFriend
Messages: 1445
Registered: July 2009
Senior Member
This appears to be a known bug in the Eclipse console view. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=159803#c10
The bug mentions some possible workarounds.

If the Eclipse C++ launcher still allows you to, try to launch your program with an external console.
Re: CDT Debug not reading EOF from console [message #1850180 is a reply to message #1850175] Sat, 19 February 2022 23:23 Go to previous messageGo to next message
Giuliano Lotta is currently offline Giuliano LottaFriend
Messages: 9
Registered: June 2016
Junior Member
@ Vavra.
Of course the program outside Eclispe works. Inside the debugger not. This means that you cannot test some parts of the program inside the debugger.
To narrow things at the bare minumum, the following code shows the SAME problem in the debug console:
int main(int argc, char * argv[]) {
	int ch = getchar();
}

If you press ctrl-D (EOF) and then Enter, the console will NEVER return the control to the debugger..
(try if you dare !! :-)

@Vegener
I found similar solutions in
https://stackoverflow.com/questions/5494958/send-an-eof-in-eclipses-debugger-console
https://stackoverflow.com/questions/4711098/passing-end-of-transmission-ctrl-d-character-in-eclipse-cdt-console

The change focus does not work.
There was also the "trick" to check "Check Use external console for inferior (open a new console window for input/output)"
BUT for what I've tried, I cannot find a similar item in the menu ... at least in 2021.12 version
Could you kindly try and find if the option it is still there "but somewhere else" ?

Thanks for your help
Giuliano
Re: CDT Debug not reading EOF from console [message #1850184 is a reply to message #1850180] Sun, 20 February 2022 15:28 Go to previous message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
program outside Eclispe works

Sure if you change it but the one you posted will go into an
infinite loop once it enters the while (ch != EOF) block as ch
can never be equal to EOF past that point because the read
at the end of the block ch = read(STDIN_FILENO, &ch, sizeof(ch)))
will never return EOF.

while (ch != EOF) {
   :   :
    ch = read(STDIN_FILENO, &ch, sizeof(ch));
}






[Updated on: Sun, 20 February 2022 15:28]

Report message to a moderator

Previous Topic:Error using ${config_name} in run configuration
Next Topic:Compile C files with g++ rather than gcc
Goto Forum:
  


Current Time: Thu Apr 18 01:50:39 GMT 2024

Powered by FUDForum. Page generated in 0.02657 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top