Author Topic: Howto debug applications which needs piped input on stdin?  (Read 8300 times)

Offline Lambertus

  • Single posting newcomer
  • *
  • Posts: 3
Howto debug applications which needs piped input on stdin?
« on: April 29, 2010, 03:48:44 pm »
Is it possible to debug an application that needs piped input on stdin using CB? If so, how?

Example: I would like to debug the application Gosmore using the following commandline in CB:

bzcat europe.osm.bz2 | ./gosmore rebuild

I've searched the forum and wiki but could only find the following topic from 2007: http://forums.codeblocks.org/index.php/topic,5056.0.html

Thanks in advance.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Howto debug applications which needs piped input on stdin?
« Reply #1 on: April 29, 2010, 08:21:26 pm »
The only way I know is to attach to the program after it has started. (Debug -> Attach to process)
You can put a sleep in the beginning of the program, so attaching would be easier.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Lambertus

  • Single posting newcomer
  • *
  • Posts: 3
Re: Howto debug applications which needs piped input on stdin?
« Reply #2 on: April 30, 2010, 01:44:29 pm »
Thanks for your tip. Attaching to the process seems to work but continuing the debugger always kills the process resulting in something like this:

Build succeeded
Starting debugger:
done
Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints
Reading symbols from /usr/lib/libxml2.so.2...(no debugging symbols found)...done.
Reading symbols from /usr/lib/libstdc++.so.6...(no debugging symbols found)...done.
Reading symbols from /lib/libm.so.6...(no debugging symbols found)...done.
Reading symbols from /lib/libgcc_s.so.1...(no debugging symbols found)...done.
Reading symbols from /lib/libc.so.6...(no debugging symbols found)...done.
Reading symbols from /lib/libdl.so.2...(no debugging symbols found)...done.
Reading symbols from /lib/libz.so.1...(no debugging symbols found)...done.
Reading symbols from /lib64/ld-linux-x86-64.so.2...(no debugging symbols found)...done.
In read () (/lib/libc.so.6)
Debugger name and version: GNU gdb (GDB) 7.1-ubuntu
Continuing...
Program exited with code 010.
Debugger finished with status 0


This happens all the time (CB 8.02) when I use 'Continue' no matter at which part of the code these options are used and even if there is a breakpoint at the next line of code. The option 'Run to cursor' seems to work a little bit better (but only sometimes and only for a few lines of code) while on the other hand, just stepping through the code with 'next line', 'step-into' and 'step-out' seems to work OK.

As this applications processes a lot of data, just stepping through is not an option, I would really like to use breakpoints. Any ideas on howto fix this?
« Last Edit: April 30, 2010, 01:47:13 pm by Lambertus »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Howto debug applications which needs piped input on stdin?
« Reply #3 on: April 30, 2010, 08:59:09 pm »
You can try a nightly build
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: Howto debug applications which needs piped input on stdin?
« Reply #4 on: May 01, 2010, 01:12:33 pm »
There is a possible workaround:

In postbuild-step add bzcat europe.osm.bz2 > europe.osm,
and add < europe.osm as program argument in "Project -> Set programs's arguments..." for the used target.

This should work if europe.osm.bz2 is in the Execution working dir of the target, otherwise you have to fix the path(s).

Offline Lambertus

  • Single posting newcomer
  • *
  • Posts: 3
Re: Howto debug applications which needs piped input on stdin?
« Reply #5 on: May 03, 2010, 08:39:42 pm »
There is a possible workaround:

In postbuild-step add bzcat europe.osm.bz2 > europe.osm,
and add < europe.osm as program argument in "Project -> Set programs's arguments..." for the used target.

This should work if europe.osm.bz2 is in the Execution working dir of the target, otherwise you have to fix the path(s).
Thanks, the "<" bit was very useful, I didn't think of it earlier. So actually its even simpler: unpack the europe.osm.bz2 outside CB just once and just add

rebuild < europe.osm

to the program's arguments...

Thanks a lot!