Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Emacs gdb interface

55 views
Skip to first unread message

Matt McClure

unread,
Mar 20, 2012, 10:58:48 PM3/20/12
to Dani Moncayo, help-emac...@gnu.org, help-gn...@gnu.org
On Tue, Mar 20, 2012 at 4:21 PM, Dani Moncayo <dmon...@gmail.com> wrote:
At this point, the *input/output of p1.exe* buffer should show the
"hello, world!" message written to the standard output, right?  But I
observe that the buffer remains empty (see attached screenshot).

Just a guess:

There is no newline in the intended output, so perhaps the output isn't flushed yet. Does it appear if you step through the rest of the program?
 
--
Matt McClure
http://www.matthewlmcclure.com
http://www.mapmyfitness.com/profile/matthewlmcclure

Dani Moncayo

unread,
Mar 21, 2012, 3:33:40 AM3/21/12
to Matt McClure, help-emac...@gnu.org, help-gn...@gnu.org
> There is no newline in the intended output, so perhaps the output isn't
> flushed yet. Does it appear if you step through the rest of the program?

I've tried it and not, it never appears, even after I've reached the
end of the program.

Thanks for answering.

BTW: I did not wrote the compilation command, which was:
gcc -g --all-warnings -Wall -Wextra -o p1.exe main.c

--
Dani Moncayo

Bob Proulx

unread,
Mar 21, 2012, 3:50:07 AM3/21/12
to Dani Moncayo, help-emac...@gnu.org, help-gn...@gnu.org
Dani Moncayo wrote:
> > There is no newline in the intended output, so perhaps the output isn't
> > flushed yet. Does it appear if you step through the rest of the program?
>
> I've tried it and not, it never appears, even after I've reached the
> end of the program.

Please add a newline to the output. I think that without the newline
the output may be covered by other output. I think it likely that the
output is actually being output but just covered.

- printf("hello, world!");
+ printf("hello, world!\n");

Bob

Peter Dyballa

unread,
Mar 21, 2012, 4:28:45 AM3/21/12
to Dani Moncayo, help-emac...@gnu.org, help-gn...@gnu.org

Am 21.3.2012 um 08:33 schrieb Dani Moncayo:

> gcc -g --all-warnings -Wall -Wextra -o p1.exe main.c

-g produces debug information in the default format, maybe you need to use -ggdb to get "debug information in default extended format". (It might also be useful to try the build with the additional switches -feliminate-unused-debug-symbols and -feliminate-unused-debug-types.)

--
Greetings

Pete

There's no place like 127.0.0.1
– origin unknown


Dani Moncayo

unread,
Mar 21, 2012, 4:39:27 AM3/21/12
to Bob Proulx, Dani Moncayo, help-emac...@gnu.org, help-gn...@gnu.org
> Please add a newline to the output.  I think that without the newline
> the output may be covered by other output.  I think it likely that the
> output is actually being output but just covered.
>
> -  printf("hello, world!");
> +  printf("hello, world!\n");

If that was the case, it would cause a lot of confusion to users, but
fortunately, that's not the case (I've just tested it and I see no
output either).

Thank you.

--
Dani Moncayo

Dani Moncayo

unread,
Mar 21, 2012, 4:43:44 AM3/21/12
to Peter Dyballa, help-emac...@gnu.org, help-gn...@gnu.org
>>   gcc -g --all-warnings -Wall -Wextra -o p1.exe main.c
>
> -g produces debug information in the default format, maybe you need to use -ggdb to get "debug information in default extended format". (It might also be useful to try the build with the additional switches -feliminate-unused-debug-symbols and -feliminate-unused-debug-types.)

I've just tried to compile like this:
gcc -ggdb --all-warnings -Wall -Wextra
-feliminate-unused-debug-symbols -feliminate-unused-debug-types -o
p1.exe main.c

But that does not help. Same result.

Alberto Luaces

unread,
Mar 21, 2012, 4:54:33 AM3/21/12
to help-gn...@gnu.org
I also think it's a buffering issue. For me, it makes a difference to
put the \n or not. It also happens if I put a fflush(0) statement after
the printf().

Your unmodified example works for me if I run the program into gdb with
the 'r' command.

--
Alberto


Bob Proulx

unread,
Mar 21, 2012, 5:28:43 AM3/21/12
to Dani Moncayo, help-emac...@gnu.org, help-gn...@gnu.org
Dani Moncayo wrote:
> > Please add a newline to the output. I think that without the newline
> > the output may be covered by other output. I think it likely that the
> > output is actually being output but just covered.
> >
> > - printf("hello, world!");
> > + printf("hello, world!\n");
>
> If that was the case, it would cause a lot of confusion to users, but
> fortunately, that's not the case (I've just tested it and I see no
> output either).

It may be confusing but it is no different from having this case:

rwp@discord:~$ printf "Hello" ; printf "\r"
rwp@discord:~$

Question: Where did the output go? Answer: It was printed but then it
was covered by the prompt and effectively hidden. Here I am using two
printf statements because your program didn't include one but in the
operation of gdm and emacs there is almost certainly one, which is
represented here by the second printf.

But since you say it didn't make any difference then this point isn't
relevant. But at least you can see why I asked for the newline.

At this point I do not have any more information. Good luck!

Bob

Dani Moncayo

unread,
Mar 21, 2012, 6:26:23 AM3/21/12
to Bob Proulx, Dani Moncayo, help-emac...@gnu.org, help-gn...@gnu.org
>> If that was the case, it would cause a lot of confusion to users, but
>> fortunately, that's not the case (I've just tested it and I see no
>> output either).
>
> It may be confusing but it is no different from having this case:
>
>  rwp@discord:~$ printf "Hello" ; printf "\r"
>  rwp@discord:~$
>
> Question: Where did the output go?  Answer: It was printed but then it
> was covered by the prompt and effectively hidden.  Here I am using two
> printf statements because your program didn't include one but in the
> operation of gdm and emacs there is almost certainly one, which is
> represented here by the second printf.

Thanks for the explanation, but what I wanted to say is that the users
expect that the "input/output" buffer in Emacs contains _exclusively_
the input/output text sent to/taken from the process, and in this
case, the process does not write any "\r" character.

In any case, as you said, this doesn't seem to be the origin of the problem.

Thanks.

--
Dani Moncayo

Sergei Organov

unread,
Mar 21, 2012, 6:53:59 AM3/21/12
to help-gn...@gnu.org, help-emac...@gnu.org
Dani Moncayo <dmon...@gmail.com> writes:

> Hello Emacs,
>
> I'm trying to test the Emacs gdb interface, but there is something I
> don't yet understand.
>
> This is my setup:
> * OS: MS-Windows 7.
> * Development Environment: MinGW.
>
> I've done this:
> * I've written a "hello world" program [1].
> * I've compiled it.
> * I've tested the executable (p1.exe), and it works fine.
>
> Now, from my Emacs (almost latest trunk) I've done:
> * M-x gdb RET (the default command was "gdb -i=mi p1.exe")
> * b main RET
> * run RET
> * M-x gdb-many-windows RET
> * n RET
>
> At this point, the *input/output of p1.exe* buffer should show the
> "hello, world!" message written to the standard output, right? But I
> observe that the buffer remains empty (see attached screenshot).
>
> Probably I'm missing something here. Do you know what?

Did you try to run it under bare gdb (without Emacs)? If the problem
remains, it's gdb issue rather than Emacs one.

-- Sergei.


Dani Moncayo

unread,
Mar 21, 2012, 8:11:02 AM3/21/12
to Sergei Organov, help-emac...@gnu.org, help-gn...@gnu.org
> Did you try to run it under bare gdb (without Emacs)? If the problem
> remains, it's gdb issue rather than Emacs one.

Good question. I've just debugged the program directly under gdb
(invoked from a cmd.exe console) and everything looks fine (I see the
"hello, world" message).

I'm beginning to consider sending an bug report.

Thanks.

--
Dani Moncayo

Doug Lewan

unread,
Mar 21, 2012, 9:32:33 AM3/21/12
to help-gn...@gnu.org
I don't think this will be regarded as a bug.

Debugger mode is derived from comint mode which, by design, doesn't display output until it gets to the end of a line.

A few details, if you care:

>From the other side, gdb doesn't see anything you type until you type <ENTER>, invoking (comint-send-input) and as a consequence calls the comint-input-filter-functions.
I think the corresponding function for output is (comint-output-filter).
These things usually do good things for you, like hide passwords.

An experiment (under *NIX), if you want an example of what comint doesn't show you:

Get a shell buffer and type 'stty sane'. (This cooks the terminal. Comint intentionally makes it raw to control I/O.
Now type a command like 'echo Your name here.'
You will also see the command since the terminal now echoes its input too.
(No, I don't know how to do this on Windows and I don't know something that corresponds for gdb. Sorry.)

I hope this helps.

,Doug

Eli Zaretskii

unread,
Mar 21, 2012, 2:51:21 PM3/21/12
to help-emac...@gnu.org, help-gn...@gnu.org
> Date: Wed, 21 Mar 2012 08:33:40 +0100
> From: Dani Moncayo <dmon...@gmail.com>
> Cc: help-emac...@gnu.org, help-gn...@gnu.org
>
> > There is no newline in the intended output, so perhaps the output isn't
> > flushed yet. Does it appear if you step through the rest of the program?
>
> I've tried it and not, it never appears, even after I've reached the
> end of the program.

If you add the newline, the output appears at the end, but not in the
input/output buffer.

If there's no newline, I wouldn't expect the output to appear at all,
in such a short program, since standard output redirected to pipes is
fully-buffered on Windows, not line-buffered as on Posix systems.

Dani Moncayo

unread,
Mar 21, 2012, 4:09:52 PM3/21/12
to Eli Zaretskii, help-emac...@gnu.org, help-gn...@gnu.org
> If you add the newline, the output appears at the end, but not in the
> input/output buffer.
>
> If there's no newline, I wouldn't expect the output to appear at all,
> in such a short program, since standard output redirected to pipes is
> fully-buffered on Windows, not line-buffered as on Posix systems.

Ok, I understand that Emacs can't show the output until it is flushed,
but when it is, as (for example) in this case:

-------- main.c -------------
#include <stdio.h>

int main(void)
{
printf("hello, world!\n");
fflush(stdout);
return 0;
}
-----------------------------

The output should not be shown in the *gud* buffer (as happens now),
but in the *input/output* one, no? If not, what's that *input/output*
buffer for?

--
Dani Moncayo

Eli Zaretskii

unread,
Mar 21, 2012, 5:30:33 PM3/21/12
to help-emac...@gnu.org, help-gn...@gnu.org
> Date: Wed, 21 Mar 2012 21:09:52 +0100
> -------- main.c -------------
> #include <stdio.h>
>
> int main(void)
> {
> printf("hello, world!\n");
> fflush(stdout);
> return 0;
> }
> -----------------------------
>
> The output should not be shown in the *gud* buffer (as happens now),
> but in the *input/output* one, no? If not, what's that *input/output*
> buffer for?

I suspect that whatever tricks gdb-mi.el uses to separate the
program's output from GDB's simply doesn't work on Windows. But
that's a guess, I didn't have time to dig into this.

0 new messages