0

I have a function that pretty prints a data structure, its function prototype is:

void print_mode(FILE *fp, Mode *mode);

the FILE* allows you to redirect the output to anywhere you want, e.g. stdout, stderr, a file etc. Mode is the data structure

I am trying to call this function from within gdb and want the output to be directed to the gdb console window, stdout?

I have tried:

(gdb) p print_mode(STDOUT,fragment_mode)
No symbol "STDOUT" in current context.
(gdb) p print_mode(stdout,fragment_mode)
$17 = void

neither of which work

any ideas how i can get the output of the function to display in the gdb console?

should add - I am using gdb within emacs 24.2.1 under linux

6
  • Try looking at info terminal, run > redirect-file and tty device-name. There will be device names that are the equivalent of stdin, stdout, ala /dev/tty Commented Dec 11, 2013 at 15:16
  • 1
    Try call print_mode(stdout,fragment_mode) instead of p print_mode(stdout,fragment_mode)? Commented Dec 11, 2013 at 15:16
  • Could STDOUT be a macro? Find out to what it expands. Commented Dec 11, 2013 at 15:40
  • @anishsane: In terms what the program itself prints out print and call shouldn't make any difference. Commented Dec 11, 2013 at 18:30
  • 1
    Let's check whether stdout has a sensible value. Does call fprintf(stdout, "test %d\n", 5) within gdb produce output? Commented Dec 11, 2013 at 18:44

2 Answers 2

2

STDOUT seems to be macro, which is not know to GDB, as handled prior to compilation by the pre-preprocessor.

Using stdout should do the job.

However the function print_mode() simply does not seem to print out anything.

In terms what's being printed to the console by the program being debugged, GDB's commands printand call should not make a difference.

For details on this you might like to read here: https://sourceware.org/gdb/onlinedocs/gdb/Calling.html


An issue might be that stdout by default is line buffered, so output would not occur before detecting a linefeed and print_mode() perhaps does not send a linefeed (\n).

To test this just use stderr as output file, as the latter isn't buffered:

p print_mode(stderr, fragment_mode)
Sign up to request clarification or add additional context in comments.

Comments

0

Oh dear - silly mistake. You're right, stdout does do the job.

I forgot that having upgraded from emacs 23 to 24, the way gdb works has changed in as much as it now opens a separate buffer *input/output of program-name* to which it redirects the output of the program being debugged. In the prior version of emacs it was all displayed in the same, single gdb buffer.

So my second attempt was actually working, I was just looking in the wrong place so didn't see the output

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.