1

I'm using kgdb to debug something via a serial cable, so I "set remote /dev/ttyS1" in gdb, which gives me output from the remote machine through gdb.

Is there any way to redirect this output to a file WITHOUT redirecting the rest of gdb's output? It won't let me enable TUI, either. I'm using:

set logging file ~/gdb_output.log
set logging overwrite on
set logging redirect on
set logging on

Thanks!

Is both the serial coming in from my target machine and the output from gdb using stdout? What uses stdin, what uses stdoutm and what uses stderr?

Jordan
  • 9,014
  • 8
  • 37
  • 47
  • Is there any part of the output strings you would like to have in the file unique that would allow you to use grep? – ryyker May 05 '14 at 23:03
  • 1
    What is the output you want to redirect, just the kernel messages (aka dmesg) or also the program output? Is it ok to disable the kernel messages output to the serial instead of "redirecting" them to a file? You could grab them after using the "dmesg" command... – Fernando Silveira May 09 '14 at 14:47
  • In this case the kernel messages are the program output coming in over serial, and that's what I want to redirect to a file. I want the GDB initiated output (i.e. not printk messages) and gdb print statements, etc, to still be in the main window. – Jordan May 09 '14 at 21:13
  • You mean like this answer here: http://stackoverflow.com/questions/5941158/gdb-print-to-file-instead-of-stdout ? – Radu C May 12 '14 at 00:37
  • @Jordan, how about [`set logging redirect off`](https://sourceware.org/gdb/download/onlinedocs/gdb/Logging-Output.html#Logging-Output)? I don't grasp what kind of workflow you're trying to set up (perhaps using `screen` to record the debugging sessions would work better?), but [GDB Manual](https://sourceware.org/gdb/download/onlinedocs/gdb/index.html) has pretty good descriptions of the debugging options.. – Nominal Animal May 12 '14 at 12:54
  • I set logging on to redirect the dmesg output from the serial console to a file. @RaduC:Yes, like that. But then it also captures the gdb-generated output. – Jordan May 12 '14 at 16:08
  • @NominalAnimal: Using screen is the same thing as setting logging to file essentially (except tty instead of to file). The issue seems to be that BOTH (?) dmesg and gdb output (such as 'print', 'info breakpoints', 'look', 'backtrace', etc) are coming from the target machine over the serial, and I can't separate them. I want the dmesg output from the target machine to go to file, and not the gdb output. – Jordan May 12 '14 at 16:10
  • @Jordan: How about logging /dev/ttyS1 transfers at the serial port, say using [interceptty](http://www.suspectclass.com/sgifford/interceptty/interceptty.html)? You'd run `sudo interceptty /dev/ttyS1 /dev/ttyS1.alt | interceptty-nicedump` first, in a separate terminal (or redirect or tee the output to a file), then start the gdb session using `set remote /dev/ttyS1.alt` ? – Nominal Animal May 12 '14 at 19:11
  • Thanks, I'll give that a try, but I guess the question is if the remote gdb debugging output comes over the serial as well when I do print or something. – Jordan May 12 '14 at 19:29
  • That seems to cause me a whole bunch of problems with gdb remote debugging, I think, and gives me garbage on the interceptty terminal. I can try playing around with it I guess though. But I think gdb output still goes through serial when remote debugging. – Jordan May 12 '14 at 19:35
  • The garbage is likely incorrect ttyS1 settings; interceptty does not copy configuration from the pseudo-tty to the real one, so you might wish to use the `-s` option to explicitly set the correct baud rate etc. On a different tack: the [manual](https://sourceware.org/gdb/download/onlinedocs/gdb/Remote-Configuration.html) mentions `set remotelogfile FILENAME` option to record the serial communications to a file; if you try that, we might find out whether the output you want is separable at the debugging end. If not, is modifying the target kernel an option? – Nominal Animal May 13 '14 at 14:59
  • Nah, modifying the target kernel isn't really an option long-term. I'll give this a try, but it's a bit convoluted and I'd prefer to not go through a middle-man, as it were :) – Jordan May 15 '14 at 22:05

1 Answers1

0

How about using a redirect with run after setting up your remote target.

  1. Start gdb without giving the debug_kernel as input:
  2. Setup your remote connection

    (gdb) set remote /dev/ttyS1

  3. Load the debug kernel file for gdb to start debugging

    (gdb) file debug_kernel

  4. Run and pipe output to a file

    (gdb) run > file_to_save_kgdb_output

Check out this documentation for reference: http://sourceware.org/gdb/onlinedocs/gdb/Input_002fOutput.html

Conrad Gomes
  • 416
  • 3
  • 7