Writing tests that use GDB - how to capture output?

I am trying to write tests that interact with GDB, but I have problems getting the result. I would like a log file to be generated that looks like it would be visible in the terminal if the test was performed manually. GDB is very stubborn when it comes to its release.

I managed to write Expect scripts that can interact with GDB and whose output can be redirected to a log file, but I do not want to write my tests in TCL. I hope to use Groovy, which is compatible with Java. For some reason, Perl Expect and ExpectJ the output of the program always goes to the terminal and cannot be redirected to the file.

I tried to start the GDB process with Java using ProcessBuilder, and it works mostly, but the output of print statements never appears on stdout and cannot be captured. I thought that if Expect works, then I will start to expect from Java and interact with GDB, but in this case most of the program output is lost, never appearing in the stdout of the created process.

So my question is: how can I write a test in Groovy (Java will be fine too) that interacts with GDB and can capture all the output?

Pseudo Code:

process = "gdb -q".execute() waitForPrompt() send("file exec") waitForPrompt() send("run") send("quit") 

Log file:

 (gdb) file exec Reading symbols from exec...done. (gdb) run Starting program: exec <... output ...> Program exited normally. (gdb) quit 
+1
java groovy gdb expect
Feb 23 '10 at 19:34
source share
2 answers

One possibility is that GDB output is reset by standard error, and you only capture standard output. You should fix this with a redirect, something like this I think:

  process = "gdb -q 2&>1".execute() 

The second hunch is that it might be worth checking out what it says "show interactive mode" in working and non-working cases. If they are different, try "disable interactive mode" before doing anything else.

The third option is to use the GDB logging tool to write the log file ("install logging file" and "set logging") and avoid the need to record the result yourself.

+1
Feb 23 '10 at 20:01
source share

If your test involves using gdb to actually debug something, unlike testing gdb itself, you should probably look into the gdb / mi interface.

+1
Feb 23 '10 at 20:45
source share



All Articles