Author Topic: [OT] unofficial MinGW GDB gdb with python released(2018-07-25)  (Read 10713 times)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
[OT] unofficial MinGW GDB gdb with python released(2018-07-25)
« on: October 06, 2017, 05:00:43 am »
The description is in the old thread, see here: [OT] unofficial MinGW GDB gdb with python released, since that thread is locked, so I created a new thread. The download binary is here: gdb2018-07-25.zip(this zip file does not contains python2.7, so you have to install a python 2.7 on your system) or gdb2018-07-25-bundle-python27.zip(this zip file already contains a python2.7), the patches are also uploaded as gdb2018-07-25patches.zip.

I have explained why my personal build of 32bit gdb is suitable for debugging a C++ program, see this post.

The change log:
2018-08-02 for those who are lazy to download and install a python2.7. I have now a new package: gdb2018-07-25-bundle-python27.zip, see this post for more details.

2018-07-25 New build against GDB git master HEAD is uploaded, and the patches are also uploaded.
 
2017-10-06 I build the gdb-git master head against my own patches(the patches are still the same as the old ones). I use the new compiler: i686-5.4.0-release-posix-dwarf-rt_v5-rev0 which is from mingw-w64 site, and I use the latest zlib and expat library from their official site. The build instructions and how to use python (the gdb need a 32bit python 2.7 environment, you can download from https://www.python.org/downloads/). More details can be from the old thread  [OT] unofficial MinGW GDB gdb with python released.
« Last Edit: August 02, 2018, 07:05:48 am by ollydbg »
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: [OT] unofficial MinGW GDB gdb with python released(2018-07-25)
« Reply #1 on: July 25, 2018, 01:11:58 am »
FYI:
The new build gdb2018-07-25 version is out, the patches are also uploaded. Please try it. :)
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: [OT] unofficial MinGW GDB gdb with python released(2018-07-25)
« Reply #2 on: July 25, 2018, 02:50:23 am »
Does the mingw-64 gdb does not have python support?

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: [OT] unofficial MinGW GDB gdb with python released(2018-07-25)
« Reply #3 on: July 25, 2018, 08:06:58 am »
Does the mingw-64 gdb does not have python support?
The gdb supplied by mingw-w64 site does have python support. But my personal build 32bit gdb has some special fixes which the they don't have.

The main issue the the "inferior call", for example, you have such code snippet.

Code
#include <iostream>

using namespace std;

class Box {
   public:
      double length;         // Length of a box
      double breadth;        // Breadth of a box
      double height;         // Height of a box

      // Member functions declaration
      double getVolume(void);
      void setLength( double len );
      void setBreadth( double bre );
      void setHeight( double hei );
};

// Member functions definitions
double Box::getVolume(void) {
   return length * breadth * height;
}

void Box::setLength( double len ) {
   length = len;
}
void Box::setBreadth( double bre ) {
   breadth = bre;
}
void Box::setHeight( double hei ) {
   height = hei;
}

// Main function for the program
int main() {
   Box Box1;                // Declare Box1 of type Box
   Box Box2;                // Declare Box2 of type Box
   double volume = 0.0;     // Store the volume of a box here

   // box 1 specification
   Box1.setLength(6.0);
   Box1.setBreadth(7.0);
   Box1.setHeight(5.0);

   // box 2 specification
   Box2.setLength(12.0);
   Box2.setBreadth(13.0);
   Box2.setHeight(10.0);

   // volume of box 1
   volume = Box1.getVolume();
   cout << "Volume of Box1 : " << volume <<endl;

   // volume of box 2
   volume = Box2.getVolume();
   cout << "Volume of Box2 : " << volume <<endl;
   return 0;
}


Now, you can set a breakpoint at the line
Code
   volume = Box1.getVolume();

And you can type the command to modify the object, see the C::B log below:

Code
> p Box1.setLength(18.0)

[debug]> p Box1.setLength(18.0)
[debug]$1 = void
[debug]>>>>>>cb_gdb:

$1 = void
> p Box1

[debug]> p Box1
[debug]$2 = {length = 18, breadth = 7, height = 5}
[debug]>>>>>>cb_gdb:

$2 = {length = 18, breadth = 7, height = 5}

You see, the object can be modified by the inferior call, while if you use the vanilla 32bit GDB or mingw-w64's current GDB, the inferior call just get failed.  I remember they use my patch some years ago, but in recent years, my patch was dropped by them, and I don't know why. This issue will happens when you try to run a member function of an object, such as if you want to call a function like std::string::length()
e.g

Code
// string::length
#include <iostream>
#include <string>

int main ()
{
  std::string str ("Test string");
  std::cout << "The size of str is " << str.length() << " bytes.\n";
  return 0;
}

Set a breakpoint at the return statement, if you type "p str.length()", you get wrong result (this is tested under msys2's 32bit mingw-w64 gdb):

Code
Debugger name and version: GNU gdb (GDB) 8.0.1
Child process PID: 4848
At E:\msys2-32bit\test\test-gdb-cpp-call\main.cpp:9
> p str.length()
$1 = 4294873232



There are other issues my build gdb fixes.  :)

I think without those patch, it is hard to debug a C++ program.


If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: [OT] unofficial MinGW GDB gdb with python released(2018-07-25)
« Reply #4 on: July 25, 2018, 05:54:33 pm »
Ok! Thank you for your writeup!

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: [OT] unofficial MinGW GDB gdb with python released(2018-07-25)
« Reply #5 on: August 02, 2018, 06:56:54 am »
FYI: for those who are lazy to download and install a python2.7. I have now a new package: gdb2018-07-25-bundle-python27.zip

So, just download and extract it, and run gdb.exe to start debugging.  ;) You don't need to install a python2.7 on your computer any more, because this gdb2018-07-25-bundle-python27.zip already bundled a python 2.7 distribution.

Here is how I create this "gdb2018-07-25-bundle-python27.zip"
I install a portable python 2.7(from this package: 20.8 MB WinPython-32bit-2.7.13.1Zero.exe, thanks to the WinPython project), and then I copy all the files in the python 2.7.13 folder to gdb's bin folder.



If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: [OT] unofficial MinGW GDB gdb with python released(2018-07-25)
« Reply #6 on: August 02, 2018, 09:23:15 am »
Quote
FYI: for those who are lazy to download and install a python2.7. I have now a new package: gdb2018-07-25-bundle-python27.zip
i reread this discussion from the forum a few days ago xD

Offline bcc32x

  • Multiple posting newcomer
  • *
  • Posts: 18

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: [OT] unofficial MinGW GDB gdb with python released(2018-07-25)
« Reply #8 on: October 12, 2018, 03:54:59 pm »
I'm using this: http://www.equation.com/servlet/equation.cmd?fa=gdb
I just see their gdb is built in year 2014, it is 4 years old.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Online nenin

  • Almost regular
  • **
  • Posts: 202
Re: [OT] unofficial MinGW GDB gdb with python released(2018-07-25)
« Reply #9 on: January 22, 2020, 08:05:28 am »
Do you plan new releases?
I found standalone distribution of the mingw64 gcc - winlibs.com  github.com/brechtsanders/winlibs_mingw - but  gdb in this distribution does not support python.