Author Topic: Redirect output of a currently debugged program to the logmanager  (Read 3648 times)

Offline MaSydJun

  • Single posting newcomer
  • *
  • Posts: 2
Redirect output of a currently debugged program to the logmanager
« on: September 12, 2013, 10:38:16 pm »
Unfortunately in Codeblocks i didn't yet find a possibility to redirect a programs' output to a seperate tab in the "Logs & others" section.
Well I know, that exact same job. But i can't use them when debugging a program. Also, I find it more convinient to just press the run-/debug-button and the output will automatically displayed in an logger window.

So I decided to simply write a plugin.
I already managed to write a message to a seperate, self-created logging-window in the "Logs & others" section, when the user presses the "debug" button (or presses [F8]).
For this purpose I read the source code of the Valgrind-plugin, which was quite straight forward.
But now I'm stuck. I don't know how to redirect the output of the program to this logging-window.
Does anyone know how to fetch the output and redirect it?

Another question, which is not related to my problem above:
As I created a new logging window in the plugin I wrote, it was very tricky to find a "free slot".
Code: [Select]
Manager::Get()->GetLogManager()->Slot(i);whereas i is the so called tab-index.
But i could just guess at which index i want to place my new logging-window and which slot is free.
Well, the first 3 indices (1, 2, 3) are already used. But all others are more or less "unknown".
I used the following piece of code to get the first free slot:
Code: [Select]
logman = Manager::Get()->GetLogManager();
// ...
for (int i = 0; i < logman->ListAvailable().size(); i++)
// check for g_null_log to indicate a free slot
if (logman->Slot(i).GetLogger() != &g_null_log)
{
free_slot_index = i;
break;
}
Now my question: Is there an easier way to do this. Cause the solution above is just a dirty hack, but it works ;)

Regards

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11939
    • Travis build status
Re: Redirect output of a currently debugged program to the logmanager
« Reply #1 on: September 12, 2013, 10:46:52 pm »
Does anyone know how to fetch the output and redirect it?
What OS?

Now my question: Is there an easier way to do this. Cause the solution above is just a dirty hack, but it works ;)
There is a proper API for this. See cbEVT_ADD_LOG_WINDOW, cbEVT_REMOVE_LOG_WINDOW and other related events.
(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 MaSydJun

  • Single posting newcomer
  • *
  • Posts: 2
Re: Redirect output of a currently debugged program to the logmanager
« Reply #2 on: September 12, 2013, 11:10:43 pm »
I Use GNU/Linux.

Actually I'm already using the cbEVT_ADD_LOG_WINDOW event.
I guess I didn't really get the point of it, because how do I determine the tab-index of the logging-window, that was createt by processing the event.
I'll research that ;)

EDIT:
Damn, it's much easier than I thought it would be...
By processing the event everything is already done. I just have to use the given logger-instance that I passed to the constructor of the CodeBlocksLogEvent-class.


------------------------------------------------
EDIT:
I guess I found something interesting: cbEVT_PIPEDPROCESS_STDOUT
Could this be able with the PipedProcess-class?
How do I get the output of the debugged program?
« Last Edit: September 12, 2013, 11:43:21 pm by MaSydJun »