Code::Blocks

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => Topic started by: ollydbg on August 08, 2011, 09:39:43 am

Title: debugger plugin feature request about the initial command of GDB
Post by: ollydbg on August 08, 2011, 09:39:43 am
Under Windows, it seems the GDB can't find it's mingw/share/gdb files, so as a workaround, I would like to start gdb using this command:

Code: [Select]
gdb --data-directory=e:/test/unix_gdb/install/mingw/share/gdb
the above code will tell gdb that absolute path of "share/gdb", currently, if you install a more recent G++ or GDB, you will find that under "share/gdb", there are python pretty printres for "std c++ library" and the "gdb command support for pretty printer".

In Codelblocks, we have no such way to run GDB, There is a "debugger initializtion commands" edit control, but it can't set the parameters when gdb started. what I want is something like:
Code: [Select]
gdb --data-directory=$(TARGET_COMPILER_DIR)/share/gdb

But I found that currently, the GDB start command is hard coded in file:
Code: [Select]
wxString GDB_driver::GetCommandLine(const wxString& debugger, const wxString& debuggee)
{
    wxString cmd;
    cmd << debugger;
    cmd << _T(" -nx");          // don't run .gdbinit
    cmd << _T(" -fullname ");   // report full-path filenames when breaking
    cmd << _T(" -quiet");       // don't display version on startup
    cmd << _T(" -args ") << debuggee;
    return cmd;
}

wxString GDB_driver::GetCommandLine(const wxString& debugger, int pid)
{
    wxString cmd;
    cmd << debugger;
    cmd << _T(" -nx");          // don't run .gdbinit
    cmd << _T(" -fullname ");   // report full-path filenames when breaking
    cmd << _T(" -quiet");       // don't display version on startup
    cmd << _T(" -pid=") << wxString::Format(_T("%d"), pid);
    return cmd;
}

So, is it possible to add an extra option on the start up command??

such as:

Code: [Select]
wxString GDB_driver::GetCommandLine(const wxString& debugger, const wxString& debuggee)
{
    wxString cmd;
    cmd << debugger;
    cmd << _T(" -nx");          // don't run .gdbinit
    cmd << _T(" -fullname ");   // report full-path filenames when breaking
    cmd << _T(" -quiet");       // don't display version on startup
    cmd << extraStartupCommand; //************************************
    cmd << _T(" -args ") << debuggee;
    return cmd;
}
Then, I would simply add extraStartupCommand with below string
Code: [Select]
--data-directory=$(TARGET_COMPILER_DIR)/share/gdb
thanks.
Title: Re: debugger plugin feature request about the initial command of GDB
Post by: oBFusCATed on August 08, 2011, 10:10:29 am
As far as I know the correct place for the pretty printers is next to the headers of the stl.
Also I think after gcc 4.5 the pretty printers are included with the stl distribution (at least on linux).
Title: Re: debugger plugin feature request about the initial command of GDB
Post by: ollydbg on August 08, 2011, 10:19:41 am
the stl pretty printer for 4.6.1 under Windows is installed in:
Code: [Select]
MinGW_gcc4.6.1release_static_win32\share\gcc-4.6.1\python\libstdcxx
Also, the gdb command support python scripts is installed in:
Code: [Select]
MinGW_gcc4.6.1release_static_win32\share\gdb\python\gdb

Title: Re: debugger plugin feature request about the initial command of GDB
Post by: reckless on August 08, 2011, 03:45:39 pm
the reason is that gdb expects a posix emultion shell eg. bash or sh to get its environment. in say msys or cygwin shell it works mostly (allthough i had a few problems with some projects under msys).

most gnu utils use getenv("somepath") to get there install location but getenv does not work under a windows environment instead you need to put the files in the same dir as gdb eg c:\gdb\gdb.exe\share\gdb files. or if the files are in lib then its c:\gdb\lib\gdb files. an example of the directory structure for windows use can be seen in the xmms2 project. its some times different than what i explained so you need to expperiment a bit.
Title: Re: debugger plugin feature request about the initial command of GDB
Post by: oBFusCATed on August 08, 2011, 04:39:51 pm
reckless: I'm not sure I've understand the second part of your post...
Title: Re: debugger plugin feature request about the initial command of GDB
Post by: ollydbg on August 08, 2011, 05:15:40 pm
Yes, gdb was not friendly handle windows style path.
I have manually hack the GDB's source code, and adjust the "data-directory" under Win32.  Now, it works OK.

I suppose that we have such file structure
gdb executable is located under:
Code: [Select]
PathToMinGW\binand the python script was located under
Code: [Select]
PathToMinGW\share\gdb
the patch can be found in gdb2011-08-08.patch (http://code.google.com/p/qp-gcc/downloads/detail?name=gdb2011-08-08.patch&can=2&q=), it includes other windows path handling problem fix.


Title: Re: debugger plugin feature request about the initial command of GDB
Post by: ironhead on August 08, 2011, 06:20:58 pm
Yes, gdb was not friendly handle windows style path.
I have manually hack the GDB's source code, and adjust the "data-directory" under Win32.  Now, it works OK.

I suppose that we have such file structure
gdb executable is located under:
Code: [Select]
PathToMinGW\binand the python script was located under
Code: [Select]
PathToMinGW\share\gdb
the patch can be found in gdb2011-08-08.patch (http://code.google.com/p/qp-gcc/downloads/detail?name=gdb2011-08-08.patch&can=2&q=), it includes other windows path handling problem fix.

This fixes the issue, but it's getting to the point where gdb (at least for windows) needs to be heavily customized to play nice with C::B.  Wouldn't an option also be to make the start command for the debugger configurable (or at least allow additional parameters), as per ollydbg's original post?
Title: Re: debugger plugin feature request about the initial command of GDB
Post by: oBFusCATed on August 08, 2011, 06:31:35 pm
Yes, I'll add an option, but I guess it won't happen soon.
Title: Re: debugger plugin feature request about the initial command of GDB
Post by: oBFusCATed on August 08, 2011, 06:34:17 pm
BTW: have you tried this command: "set data-directory" http://sourceware.org/gdb/onlinedocs/gdb/Data-Files.html ?
Title: Re: debugger plugin feature request about the initial command of GDB
Post by: reckless on August 08, 2011, 07:37:05 pm
Quote
reckless: I'm not sure I've understand the second part of your post...

just trying to explain how it could be made to work without hacking the code :) most times if not in a posix shell i found that the tools could be made to work if i moved the folders containing data to where the executable is.
Title: Re: debugger plugin feature request about the initial command of GDB
Post by: xunxun on August 09, 2011, 01:17:01 pm
I have an another method.
Create a new file named ".gdbinit" at the gdb.exe directory.
Content:
Code: [Select]
set data-directory E:\MyPack\MinGW\share\gdb
Then gdb will use this data directory.
Title: Re: debugger plugin feature request about the initial command of GDB
Post by: ironhead on August 09, 2011, 02:13:58 pm
I have an another method.
Create a new file named ".gdbinit" at the gdb.exe directory.
Content:
Code: [Select]
set data-directory E:\MyPack\MinGW\share\gdb
Then gdb will use this data directory.

Unfortunately this won't help due to how gdb is started within C::B.  As per ollydbg's original post, gdb is started with "-nx" meaning .gdbinit is not sourced.

Title: Re: debugger plugin feature request about the initial command of GDB
Post by: xunxun on August 09, 2011, 02:31:23 pm
I have an another method.
Create a new file named ".gdbinit" at the gdb.exe directory.
Content:
Code: [Select]
set data-directory E:\MyPack\MinGW\share\gdb
Then gdb will use this data directory.

Unfortunately this won't help due to how gdb is started within C::B.  As per ollydbg's original post, gdb is started with "-nx" meaning .gdbinit is not sourced.


so we can use the command :
gdb -ex "set data-directory e:\mypack\mingw\share\gdb"

but I try to use "info pretty-printer", and this doesn't work.
Title: Re: debugger plugin feature request about the initial command of GDB
Post by: xunxun on August 09, 2011, 02:43:57 pm
I have an another method.
Create a new file named ".gdbinit" at the gdb.exe directory.
Content:
Code: [Select]
set data-directory E:\MyPack\MinGW\share\gdb
Then gdb will use this data directory.

Unfortunately this won't help due to how gdb is started within C::B.  As per ollydbg's original post, gdb is started with "-nx" meaning .gdbinit is not sourced.


so we can use the command :
gdb -ex "set data-directory e:\mypack\mingw\share\gdb"

but I try to use "info pretty-printer", and this doesn't work.
I test this, this method can modify the gdb's data directory, but not python's.
Title: Re: debugger plugin feature request about the initial command of GDB
Post by: oBFusCATed on August 09, 2011, 02:46:55 pm
Unfortunately this won't help due to how gdb is started within C::B.  As per ollydbg's original post, gdb is started with "-nx" meaning .gdbinit is not sourced.
You can source ~/.gdbinit manually.
You can even import the pretty printers manually.
This is what I was doing not long ago.

so we can use the command :
gdb -ex "set data-directory e:\mypack\mingw\share\gdb"
Why would you do this instead of passing --data-dir?
Title: Re: debugger plugin feature request about the initial command of GDB
Post by: ollydbg on August 09, 2011, 02:55:01 pm
@xunxun, here is the log of gdb (without the hack of gdb's share path), it shows both worked and un-worked condition.

Quote
E:\test\unix_gdb\install\mingw\bin>gdb --data-directory=e:/test/unix_gdb/install
/mingw/share/gdb
GNU gdb (GDB) 7.3.50.20110808-cvs
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "mingw32".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
(gdb) info pretty-printer
(gdb) q

E:\test\unix_gdb\install\mingw\bin>gdb
GNU gdb (GDB) 7.3.50.20110808-cvs
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "mingw32".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
(gdb) info pretty-printer
Undefined info command: "pretty-printer".  Try "help info".
(gdb)

the gdb's shared folder is used when it's python module is initialized. but the python module is running before you "set-directory" command.
so the only way to set the data-directory is setting that path as gdb parameters, like "gdb --data-directory=XXX"

the other way such as “set data-directory XXX” can not work.



Title: Re: debugger plugin feature request about the initial command of GDB
Post by: xunxun on August 09, 2011, 02:57:59 pm
so we can use the command :
gdb -ex "set data-directory e:\mypack\mingw\share\gdb"
Why would you do this instead of passing --data-dir?
[/quote]
I want to make gdb auto source this script, but .gdbinit must be in the current directory, so "-ex" only is the test.
Title: Re: debugger plugin feature request about the initial command of GDB
Post by: xunxun on August 09, 2011, 03:01:04 pm

the gdb's shared folder is used when it's python module is initialized. but the python module is running before you "set-directory" command.
so the only way to set the data-directory is setting that path as gdb parameters, like "gdb --data-directory=XXX"

the other way such as “set data-directory XXX” can not work.
Can we redefine gdb.PYTHONDIR to gdb's data directory in python.c?
Title: Re: debugger plugin feature request about the initial command of GDB
Post by: oBFusCATed on January 09, 2012, 11:23:07 pm
I've added an option to set custom arguments to gdb, please test it and report if it really works.
Title: Re: debugger plugin feature request about the initial command of GDB
Post by: ollydbg on January 10, 2012, 01:59:16 am
I've added an option to set custom arguments to gdb, please test it and report if it really works.
I will test it ASAP, currently I can't synchonize SVN now due to network issue. :)
Title: Re: debugger plugin feature request about the initial command of GDB
Post by: ollydbg on January 11, 2012, 02:10:42 am
I've added an option to set custom arguments to gdb, please test it and report if it really works.

Setting gdb startup arguments works fine.

Thank you!

PS:
Under MinGW, if you would like to Automatically load gdb's own python pretty script, you still  need to hack the gdb's source code, as I said before, it can't be done by pass the "-data-directory ...." in the gdb's startup arguments.