Author Topic: Tracing by printfs  (Read 5648 times)

Offline resander

  • Multiple posting newcomer
  • *
  • Posts: 49
Tracing by printfs
« on: December 30, 2009, 07:28:09 pm »
On Ubuntu 8.10 and codeblocks 5911.

Sometimes it is useful to put printfs into callbacks to trace progress while at the same time remaining in codeblocks to debug the non-callback code.

Then the printfs go to the codeblocks terminal screen (a GTK window?). Usually I find that the trace information does not fit on this screen and the text at the top just scrolls off. It would be useful if this window had a vertical scrollbar and also supported copy-to-clipboard.

Is that possible now? If not, it would certainly go onto my wish list.


Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: Tracing by printfs
« Reply #1 on: December 30, 2009, 10:17:14 pm »
If you mean the screen opened by C::B when running (for example) console-programs, it's by default xterm, you can set arguments in "Settings -> Environment -> Terminal to launch console programs:"
« Last Edit: December 30, 2009, 10:26:56 pm by jens »

Offline resander

  • Multiple posting newcomer
  • *
  • Posts: 49
Re: Tracing by printfs
« Reply #2 on: December 31, 2009, 03:26:27 pm »
The window I refer to (the cb console window?) shows the project name in the titlebar and has a black background. It can receive printf output issued by Normal and GTK projects. It can also wait for input via getchar etc, so it behaves like a commandline terminal but has no scrollbar and ability to copy to clipboard. If I click on close button at topright hand corner of the cb console window then the cb console window and the program being debugged both close.

If I run the same program from the Ubuntu command line it would output onto the Ubuntu terminal screen like this:

ken@ken-desktop:~$ /home/ken/projects/dragdroptreevu/bin/Debug/dragdroptreevu
on_selection_changed: "row3"|"item 43"|37|64.400002|
on_drag_data_get: DATA @ 0x8e9abe8
 |->row = row3
 |->item = item 43
 |->qty = 37
 +->price = 64.400002
on_drag_data_received:
on_drag_data_delete
selector = 148248256
BEFORE remove depth 1 index 2
on_selection_changed: No row selected 2 (onselchg)
AFTER remove GtkTreeView
on_selection_changed: "row5"|"item 68"|42|34.400002|
on_drag_data_get: DATA @ 0x8e8a4e0
 |->row = row5

All lines above after the program invocation line are output by printfs. This Ubuntu terminal screen has a scrollbar and supports copy to clipboard.

When running the program from codeblocks the printfs in callbacks go to the cb console window. The latter has no scrollbar so tracing info is usually lost.

Is there a way using current codeblocks to request a scrollbar for the cb console window?

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: Tracing by printfs
« Reply #3 on: December 31, 2009, 03:45:28 pm »
As I wrote C::B uses xterm as default console-window on linux.

You can use some (not all) other terminal emulators, by changing "Settings -> Environment -> Terminal to launch console programs:" .

I use xfce4-terminal -T $TITLE -x here, because xfce4 is my desktop environment.

You can configure the default xterm to fit your needs, but it is not so comfortable to do this (in my opinion).
Apart from the man-page a quick web-search gave me this sites: http://linuxhelp.blogspot.com/2005/10/configuring-xterm-in-linux.html and http://how-to.wikia.com/wiki/How_to_configure_xterm .

By the way you should be able to scroll through xterm using the mousewheel, even if there is no scrollbar visible.

Offline resander

  • Multiple posting newcomer
  • *
  • Posts: 49
Re: Tracing by printfs
« Reply #4 on: December 31, 2009, 08:15:28 pm »
Many thanks for your patience Jens.

As an old Windowser I just didn't understand your first response that referred to XTERM termininal that I had never heard of, so I thought I had been unclear in the original post and rephrased it. I am slightly less ignorant now!

As I am on Ubuntu that uses the GNOME desktop I want to use the GNOME terminal as codeblock's console screen. I put 'gnome-terminal' into Settings->Environment dialog which brought up the following on the gnome terminal screen after selecting Run from codeblocks:

ken@ken-desktop:~/projects/dragdroptreevu$

which is the project path to the program. The executable in this case is also called dragdroptreevu and is stored in bin/Debug, so adding bin/Debug/dragdroptreevu to the command line and pressing return executes the program which then runs with its own topwindow side-by-side with the gnome terminal. The gnome-terminal has a scrollbar and supports clipboard operations which is exactly what I wanted.

Changing the Settings->Environment for terminal choice to

  gnome-terminal -e "bin/Debug/dragdroptreevu"

starts the gnome-terminal and the program in the same way the default xterm terminal choice did. Nice.

But, the 'dragdroptreevu' executable name is a project setting that should not be hardwired in the environment terminal choice string. Is there an environment variable (or some other notation) for the program executable name that I could use instead of  hardwiring, or a variable for the projectname which is same as the executable name in my programs?


Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: Tracing by printfs
« Reply #5 on: December 31, 2009, 08:35:56 pm »
Just put
Code
gnome-terminal -t $TITLE -x
into the text-box, note "-x" has to be the last argument.
C::B adds what it needs to call your program dynamically.

Offline resander

  • Multiple posting newcomer
  • *
  • Posts: 49
Re: Tracing by printfs
« Reply #6 on: December 31, 2009, 09:45:17 pm »
Many thanks Jens,

Problem 110% solved!!!!!

gnome-terminal -t $TITLE -x is all needed for the settings->environment->terminalchoice for Ubuntu.

Jens, thank you again for your patience with us dumb-heads over the year of course for your timely cb updates via Ubuntu which are absolutely great.

It is now 20:30 UK time here on 31 Jan, so let me wish you Jens and all the CB seniors   

A Happy New Year!