Code::Blocks Forums

User forums => Embedded development => Topic started by: themaddin on February 16, 2012, 12:21:18 pm

Title: CodeBlocks and Codesourcery GDB
Post by: themaddin on February 16, 2012, 12:21:18 pm
Hello everyone,

is somebody out there who is debugging with Codeblocks and Codesourcery GDB?
I have troubles debugging with Codeblocks and Codesourcery GDB. It seems Codesourcery executes every GDB instruction from Codeblocks twice.


Debuggers log with Codesourcery GDB:
Code
[debug]GNU gdb (Sourcery CodeBench Lite 2011.09-69) 7.2.50.20100908-cvs
[debug]Copyright (C) 2010 Free Software Foundation, Inc.
[debug]License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
[debug]This is free software: you are free to change and redistribute it.
[debug]There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
[debug]and "show warranty" for details.
[debug]This GDB was configured as "--host=i686-mingw32 --target=arm-none-eabi".
[debug]For bug reporting instructions, please see:
[debug]<https://support.codesourcery.com/GNUToolchain/>.
[debug]>>>>>>cb_gdb:GNU gdb (Sourcery CodeBench Lite 2011.09-69) 7.2.50.20100908-cvs
[debug]> set confirm off

Debugger name and version: GNU gdb (Sourcery CodeBench Lite 2011.09-69) 7.2.50.20100908-cvs

[debug]Copyright (C) 2010 Free Software Foundation, Inc.
[debug]License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
[debug]This is free software: you are free to change and redistribute it.
[debug]There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
[debug]and "show warranty" for details.
[debug]This GDB was configured as "--host=i686-mingw32 --target=arm-none-eabi".
[debug]For bug reporting instructions, please see:
[debug]<https://support.codesourcery.com/GNUToolchain/>.
[debug]>>>>>>cb_gdb:
[debug]> set width 0
[debug]>>>>>>cb_gdb:>>>>>>cb_gdb:
[debug]> set height 0
[debug]>>>>>>cb_gdb:>>>>>>cb_gdb:>>>>>>cb_gdb:>>>>>>cb_gdb:
[debug]> set breakpoint pending on
[debug]>>>>>>cb_gdb:>>>>>>cb_gdb:
[debug]> set print asm-demangle on
[debug]>>>>>>cb_gdb:>>>>>>cb_gdb:
[debug]> set unwindonsignal on
[debug]>>>>>>cb_gdb:>>>>>>cb_gdb:
[debug]> set print elements 0
[debug]>>>>>>cb_gdb:>>>>>>cb_gdb:
[debug]> set debugevents on
[debug]No symbol table is loaded.  Use the "file" command.
[debug]No symbol table is loaded.  Use the "file" command.
[debug]>>>>>>cb_gdb:>>>>>>cb_gdb:
[debug]> set new-console on
[debug]No symbol table is loaded.  Use the "file" command.
[debug]No symbol table is loaded.  Use the "file" command.
[debug]>>>>>>cb_gdb:>>>>>>cb_gdb:
[debug]> set disassembly-flavor att
[debug]No symbol table is loaded.  Use the "file" command.
[debug]No symbol table is loaded.  Use the "file" command.
[debug]>>>>>>cb_gdb:>>>>>>cb_gdb:
[debug]> catch throw
[debug]No symbol table is loaded.  Use the "file" command.
[debug]No symbol table is loaded.  Use the "file" command.
[debug]Catchpoint 1 (throw)
[debug]>>>>>>cb_gdb:Catchpoint 2 (throw)
[debug]> source C:\CodeBlocks_NB7790sa\share\codeblocks/scripts/stl-views-1.0.3.gdb
[debug]>>>>>>cb_gdb:
[debug]> directory D:/cb_projects/mysecproject/
[debug]>>>>>>cb_gdb:
[debug]> run
[debug]>>>>>>cb_gdb:
[debug]Don't know how to run.  Try "help target".
[debug]>>>>>>cb_gdb:>>>>>>cb_gdb:>>>>>>cb_gdb:>>>>>>cb_gdb:
Every confirmation appears twice.


With Yagarto GDB everything is fine:
Code
[debug]GNU gdb (GDB) 7.2
[debug]Copyright (C) 2010 Free Software Foundation, Inc.
[debug]License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
[debug]This is free software: you are free to change and redistribute it.
[debug]There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
[debug]and "show warranty" for details.
[debug]This GDB was configured as "--host=i686-pc-mingw32 --target=arm-none-eabi".
[debug]For bug reporting instructions, please see:
[debug]<http://www.gnu.org/software/gdb/bugs/>.
[debug]>>>>>>cb_gdb:
[debug]> set confirm off

Debugger name and version: GNU gdb (GDB) 7.2

[debug]>>>>>>cb_gdb:
[debug]> set width 0
[debug]>>>>>>cb_gdb:
[debug]> set height 0
[debug]>>>>>>cb_gdb:
[debug]> set breakpoint pending on
[debug]>>>>>>cb_gdb:
[debug]> set print asm-demangle on
[debug]>>>>>>cb_gdb:
[debug]> set unwindonsignal on
[debug]>>>>>>cb_gdb:
[debug]> set print elements 0
[debug]>>>>>>cb_gdb:
[debug]> set debugevents on
[debug]No symbol table is loaded.  Use the "file" command.
[debug]>>>>>>cb_gdb:
[debug]> set new-console on
[debug]No symbol table is loaded.  Use the "file" command.
[debug]>>>>>>cb_gdb:
[debug]> set disassembly-flavor att
[debug]No symbol table is loaded.  Use the "file" command.
[debug]>>>>>>cb_gdb:
[debug]> catch throw
[debug]No symbol table is loaded.  Use the "file" command.
[debug]Catchpoint 1 (throw)
[debug]>>>>>>cb_gdb:
[debug]> source C:\CodeBlocks_NB7790sa\share\codeblocks/scripts/stl-views-1.0.3.gdb
[debug]>>>>>>cb_gdb:
[debug]> directory D:/cb_projects/mysecproject/
[debug]>>>>>>cb_gdb:
[debug]> run
[debug]Don't know how to run.  Try "help target".
[debug]>>>>>>cb_gdb:

Kind regards
themaddin
Title: Re: CodeBlocks and Codesourcery GDB
Post by: Lost_Byte on March 11, 2012, 10:09:12 am
I have the same behavior.
Let me know, if you solved this problem.

P.S. I'm using Code::Blocks about 3 years in Embedded Linux Developing for targets, such as: ATMEL ARM9, AVR, Marvell PXA based systems. This problem became with new (for me) TI-Sitara based platform, and ARM GNU/Linux Sourcery G++ Lite 2009q1-203
Title: Re: CodeBlocks and Codesourcery GDB
Post by: oBFusCATed on March 11, 2012, 11:14:19 am
Lost_Byte: This is a known problem, but it is not ours problem.
See this for discussion: http://forums.codeblocks.org/index.php/topic,15947.0.html

If you're interested in this been fixed you should contact the codesourcery's support.
Title: Re: CodeBlocks and Codesourcery GDB
Post by: scarphin on March 11, 2012, 01:07:16 pm
For an update by my side, I tried to contact the only e-mail address I could find on their site and both my e-mails returned undelivered. I won't go further.
Title: Re: CodeBlocks and Codesourcery GDB
Post by: Lost_Byte on March 16, 2012, 06:43:43 am
OK. Will be brief.
Code Sourcery did not respond. It's not surprising, becouse of Lite is "as is" toolchain, end there is propietary Code Bench.
C::B Developer (i guessed) oBFusCATed said:
This is unfortunate.

Note: Change of plans, anyone having this problem and wanting it being fixed should talk to codesourcery's support/dev/gdb maintainers.
I don't intend to support every quirk in every different gdb release.

If you don't want to talk to codesourcery's support your only chance is to patch c::b yourself.

I've solved this that way: Simple win32 console app that provides tunneling for stdin,stdout,stderr with filtering '\r' in stdin tunnel.

Usage:
1. Place gdb-cb-bridge.exe and gdb-cb-bridge.cfg into your Code Sourcery "/bin" directory, beside [arm-none-gnueaby-,or whatever prefix]-gdb.exe tool.  File gdb-cb-bridge.cfg contain nothing but your gdb tool filename (i.e. [prefix-]gdb.exe).
2. In "Main Menu">"Settings">"Compiler and Debugger">"Toolchain executables">"Debugger" just replace [prefix-]gdb.exe to gdb-cb-bridge.exe

Attached files:
 exec, cfg-example (my cfg), project and source (sorry, almost uncommented).

Regards!
Title: Re: CodeBlocks and Codesourcery GDB
Post by: oBFusCATed on March 16, 2012, 08:47:44 am
Does setting breakpoints on the fly (while the debuggee/inferior is running) work?
Title: Re: CodeBlocks and Codesourcery GDB
Post by: Lost_Byte on March 16, 2012, 09:58:04 am
Does setting breakpoints on the fly (while the debuggee/inferior is running) work?

Oh... I hope, understood the question correctly ...
I can set breakpoint while debuggee/inferior is running, and "red point" appears on source view. But this takes effect (debugged process stops at breakpoint) only after sending SIGINT to the process.
And I have the same behavior on others gdb such as builded from scratch or provided by SoC/mC manufacturers.
Title: Re: CodeBlocks and Codesourcery GDB
Post by: oBFusCATed on March 16, 2012, 10:01:42 am
If I understand you answer correctly it doesn't work out of the box?
The other test you can do is to press the pause button, while the debuggee is running.
If this works then the breakpoints should work, too.
Title: Re: CodeBlocks and Codesourcery GDB
Post by: Lost_Byte on March 16, 2012, 10:14:32 am
The other test you can do is to press the pause button, while the debuggee is running.

No, it does not work.
Title: Re: CodeBlocks and Codesourcery GDB
Post by: oBFusCATed on March 16, 2012, 11:02:38 am
Can you give detailed explanation how to fix the problem?
Title: Re: CodeBlocks and Codesourcery GDB
Post by: Lost_Byte on March 16, 2012, 01:00:43 pm
Can you give detailed explanation how to fix the problem?

Explanation...

Sorry, my English is not very well. But I'll try to explain correctly.

Initial conditions:
IDE C::B 10.5
Toolchain: CodeSourcery G++ Lite (arm-2011.03-41 arm-none-linux-gnueabi)
Host: i686-pc
Target (uname -a output): Linux am180x-evm 3.2.0-rc3+ #122 PREEMPT Fri Mar 16 10:54:28 MSK 2012 armv5tejl unknown

Debugging - i.e. remote debugging through TCP, gdbserver is running on target, gdb.exe is running on host.
CodeSourcery gdb.exe stdio passing through the gdb-cb-brige.

Such features as setting breakpoints, disassembling, variable inspecting and other work perfectly until gdbserver inferior (debugging process) is STOPPED. (At break point, after SIGINT, or until "continue" command have not sended since debugging had started)

After "continue" command, (i.e. inferior is RUNNING) there are only two cases, when inferior will stop:
1. Inferior obtains breakpoint setted before "continue" command;
2. Inferior gets a SIGINT signal( to do that just press CTRL+c if inferior is a console app).

When inferior is running, button "Stop debuger" or setting breakpoints and other options do not take effect.
Certainly, because of there are no gdb prompt.

The same behavior takes all combination of IDE+gdb+gdbserver (or GUI-frontend+gdb+gdbserver) i have seen, except gdbs which have been working through JTAG hardware ISE's.
Probably is it a feature of remote debugging? Or maybe I don't understand something?
Of course, it's fine to have ability to stop debugging procces anywhere/anytime, but, in my opinion, that's not really needs in practice.

So, my sketch (gdb-cg-bridge) fixs incompatibility besides C::B and CodeSourcery gdb in my case.
Title: Re: CodeBlocks and Codesourcery GDB
Post by: oBFusCATed on March 16, 2012, 01:05:48 pm
Hm, I thought you've using the latest version of the debugger's branch nightly.
Please try it and then report if the pause button works.

BTW. What is your native OS?
Title: Re: CodeBlocks and Codesourcery GDB
Post by: Lost_Byte on March 16, 2012, 01:55:11 pm
Hm, I thought you've using the latest version of the debugger's branch nightly.
Please try it and then report if the pause button works.

What do you mean in "debugger's branch nightly"?

BTW. What is your native OS?

My HOST OS (for development,and where C::B is running) is WIN-XP SP3
Title: Re: CodeBlocks and Codesourcery GDB
Post by: oBFusCATed on March 16, 2012, 02:10:34 pm
See there: http://forums.codeblocks.org/index.php/board,20.0.html
Title: Re: CodeBlocks and Codesourcery GDB
Post by: Lost_Byte on March 19, 2012, 10:09:06 am
Please try it and then report if the pause button works.

It does not works.
The same behavior.
Title: Re: CodeBlocks and Codesourcery GDB
Post by: oBFusCATed on March 19, 2012, 11:12:19 am
Does you executable captures Ctrl+C/SIGINT and after that resending it to the real GDB?
If not can you try to implement it and report if this is working?
Keep in mind that you have to have a console allocated in order for this to work.
Title: Re: CodeBlocks and Codesourcery GDB
Post by: Lost_Byte on March 19, 2012, 11:45:49 am
Does you executable captures Ctrl+C/SIGINT and after that resending it to the real GDB?

How should it looks?

After SIGINT to debugging exec in C::B "Debugger(debug)" log view contains following (my comments under ///):
/// run exec to while(1) loop...
> continue
/// send CTRL+C
Cannot access memory at address 0x0
Program received signal SIGINT, Interrupt.
0x402b9d58 in ?? ()
>>>>>>cb_gdb:
/// some commands by debugee to obtain current exec state
Title: Re: CodeBlocks and Codesourcery GDB
Post by: oBFusCATed on March 19, 2012, 11:56:24 am
I don't understand your question. Can you clarify it a bit?
Title: Re: CodeBlocks and Codesourcery GDB
Post by: Lost_Byte on March 19, 2012, 12:17:03 pm
Does you executable captures Ctrl+C/SIGINT and after that resending it to the real GDB?

What did you mean under "resending"?
How should it looks for me during debugging session under C::B?
Title: Re: CodeBlocks and Codesourcery GDB
Post by: Lost_Byte on March 19, 2012, 12:29:47 pm
Does you executable captures Ctrl+C/SIGINT and after that resending it to the real GDB?

Oh.. It seems, I got it... "Executable"- means, my "gdb-cb-bridge" sketch? Is it?
If it's so - answer, no, "gdb-cb-bridge" does not handle SIGINT... I'll try to implement.
Title: Re: CodeBlocks and Codesourcery GDB
Post by: oBFusCATed on March 19, 2012, 12:33:33 pm
Yes, your executable (gdb-cb-bridge).

Some notes written before your last post:
See this: http://msdn.microsoft.com/en-us/library/windows/desktop/ms686016%28v=vs.85%29.aspx

The idea is that your application should capture the ctrl-c event and then you send the same event to gdb.
When using remote debugging this is the only way to stop gdb/inferior/debuggee.
Title: Re: CodeBlocks and Codesourcery GDB
Post by: ricardo on March 20, 2012, 12:16:52 am
OK. Will be brief.
Code Sourcery did not respond. It's not surprising, becouse of Lite is "as is" toolchain, end there is propietary Code Bench.

Hello.  I'm not CodeSourcery support, but the Lite edition tools do have some community mailing lists associated with them.  See http://sourcerytools.com/ for information on how to post to those mailing lists.
Title: Re: CodeBlocks and Codesourcery GDB
Post by: Lost_Byte on March 20, 2012, 07:59:22 am

The idea is that your application should capture the ctrl-c event and then you send the same event to gdb.
When using remote debugging this is the only way to stop gdb/inferior/debuggee.

ОК. I've implemented that.
It works in command-line debug session: CTRL+C in gdb-cb-brige becomes a CTRL_C_EVENT for gdb, and it stops the inferior and shows command-prompt.
It does not works under C::B Nightly 11 February 2012 build (7789).

New build of gdb-cb-bridge is in attach.
Title: Re: CodeBlocks and Codesourcery GDB
Post by: Lost_Byte on March 26, 2012, 06:40:16 am
The idea is that your application should capture the ctrl-c event and then you send the same event to gdb.
When using remote debugging this is the only way to stop gdb/inferior/debuggee.

Hi, oBFusCATed !
Have you probed new build of gdb-cb-brige? Is there something wrong in implementation?
Title: Re: CodeBlocks and Codesourcery GDB
Post by: oBFusCATed on March 26, 2012, 09:37:32 am
I've never tried this bridge, I run linux and also don't use any embedded debugger/compiler.
Title: Re: CodeBlocks and Codesourcery GDB
Post by: Lost_Byte on March 26, 2012, 09:45:04 am
Hmmm... For some reason, I thought you were going to work out the feature to stop the debugging process on the fly...
Title: Re: CodeBlocks and Codesourcery GDB
Post by: oBFusCATed on March 26, 2012, 09:51:44 am
If cb-gdb-bridge does correctly the ctrl-c re-translation it should work. But I can't guarantee as I've not tried it.
Also getting this console stuff right is pretty tough. I've done many tests in order to make the current implementation work correctly.
I've not tried it since I've implemented it, so I don't know if it still works.
Title: Re: CodeBlocks and Codesourcery GDB
Post by: Lost_Byte on March 26, 2012, 10:24:57 am
With what gdb this feature were verified? I would like to try.
The fact that I also use cygwin-GDB for one of my platforms (without bridge), and stopping on the fly from a C::B does not work either.
Checked on Nightly build too.
Title: Re: CodeBlocks and Codesourcery GDB
Post by: oBFusCATed on March 26, 2012, 10:36:21 am
Normal gdb used for remote debugging to debug a console application.
I've not tried cygwin.
Title: Re: CodeBlocks and Codesourcery GDB
Post by: Lost_Byte on March 26, 2012, 02:48:27 pm
Sorry colleagues!
I've found stupid mistake, that leads to overbuffering in some conditions.
That's new build.
Title: Re: CodeBlocks and Codesourcery GDB
Post by: ziss_dm on April 20, 2012, 10:51:19 am
Hi,

I have spent some time investigating this issue and found the following:
1) The CodeSourcery gdb is compilled with version of MinGW which uses both \r  and \n as an EOL
2) The wxWidget text stream is converting \n to the \n\r

As a result gdb receives 2 EOLs.

This is a quick fix:
Code

void PipedProcess::SendString(const wxString& text)
{
    //Manager::Get()->GetLogManager()->Log(m_PageIndex, cmd);
    wxOutputStream* pOut = GetOutputStream();
    if (pOut)
    {
        wxTextOutputStream sin(*pOut);
        sin.SetMode(wxEOL_UNIX);
        wxString msg = text + _T('\n');
        sin.WriteString(msg);
    }
}


which works fine on windows.

This is a test build:
http://mwc-ng.googlecode.com/files/CodeBlocks_svn_gdb.zip

regards,
ziss_dm
Title: Re: CodeBlocks and Codesourcery GDB
Post by: ollydbg on April 20, 2012, 11:14:16 am
Hi,

I have spent some time investigating this issue and found the following:
1) The CodeSourcery gdb is compilled with version of MinGW which uses both \r  and \n as an EOL
2) The wxWidget text stream is converting \n to the \n\r

As a result gdb receives 2 EOLs.

This is a quick fix:
Code

void PipedProcess::SendString(const wxString& text)
{
    //Manager::Get()->GetLogManager()->Log(m_PageIndex, cmd);
    wxOutputStream* pOut = GetOutputStream();
    if (pOut)
    {
        wxTextOutputStream sin(*pOut);
        sin.SetMode(wxEOL_UNIX);
        wxString msg = text + _T('\n');
        sin.WriteString(msg);
    }
}


which works fine on windows.

This is a test build:
http://mwc-ng.googlecode.com/files/CodeBlocks_svn_gdb.zip

regards,
ziss_dm
I think you can supply a patch, so that debugger developers (mostly obf) can quickly review it. (I'm not familiar with gdb for embedded system)
Title: Re: CodeBlocks and Codesourcery GDB
Post by: oBFusCATed on April 20, 2012, 11:28:11 am
ziss_dm:
Search the forum. I've investigated this issue and have made a better patch.
I won't commit it because Codesourcery devs should fix their gdb or give plausible reason for this behaviour.
If you know how to contact them, please do so or provide the contact details in this topic or on PM.
Title: Re: CodeBlocks and Codesourcery GDB
Post by: ziss_dm on April 22, 2012, 03:09:03 am
Hi OBF,

Quote
Search the forum. I've investigated this issue and have made a better patch.

Sorry about that..  ::)

And I think you right, it would be ideal if CS could fix that. But I do not think, they going to do that in nearest future.  :) From other point of view, it is quite safe to assume \n as EOL on windows. So, if you could limit this change only for windows and post patch, it would be really helpful...

regards,
ziss_dm
Title: Re: CodeBlocks and Codesourcery GDB
Post by: martind on May 28, 2012, 11:22:56 am
Just in case you are not aware, ARM are sponsoring a GCC project now: https://launchpad.net/gcc-arm-embedded

However, not tried with CodeBlocks yet.


Martin.
Title: Re: CodeBlocks and Codesourcery GDB
Post by: MF on June 11, 2012, 01:47:02 am
I've tried the GCC ARM toolchain at Launchpad.net.  I ran into a problem using it with the J-Link GDB Server.  After connecting to the GDB Server it would always throw the following error: "Remote 'g' packet is too long".  The Codesourcery toolchain's GDB client does not have this problem.
Title: Re: CodeBlocks and Codesourcery GDB
Post by: oBFusCATed on June 11, 2012, 07:56:04 am
MF:
Does it work from the command line?
If it doesn't it is not C::B's problem...
Title: Re: CodeBlocks and Codesourcery GDB
Post by: martind on June 20, 2012, 11:42:06 pm
I know an openocd developer and he says the remote 'g' packet problem was fixed a while back. However problem actually lied with CodeSourcery?

If you get more recent version of OpenOCD problem should be fixed.
Title: Re: CodeBlocks and Codesourcery GDB
Post by: Dvorkin on February 26, 2014, 11:22:18 am
There is not allowable "carriage return" at the end of gdb exe name in the gdb-cb-brige.cfg