Author Topic: Patch for codeblocks 20.03 adding multi columns in memory dump  (Read 18709 times)

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Patch for codeblocks 20.03 adding multi columns in memory dump
« Reply #15 on: February 14, 2021, 08:29:41 pm »
I don't see any UI for it, so I guess it is something new. This was my question actually.

Note: There is the "Value Tooltip Font" option. If you want to add a font setting do it in a similar fashion.
(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 BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Patch for codeblocks 20.03 adding multi columns in memory dump
« Reply #16 on: February 14, 2021, 10:29:05 pm »
Because they are expensive? I think you've requested it this way.
I'm not sure memory watches and examine memory should be treated the same way using the same API, but I might be wrong.

@bluehazzard: Another reason might be that the request update is expected to come from the UI. Somewhere in your plugin you'll have to probably request an update when you detect that the cursor has changed.
Yea, i found out today... It would really help to add some comments to the events to indicate when they are fired.... because i was thinking cbEVT_DEBUGGER_PAUSED was send when the debugger halts, and i can request the memory, but i was wrong, i have to listen an cbEVT_DEBUGGER_CURSOR_CHANGED event...

Offline MicroSourceCode

  • Multiple posting newcomer
  • *
  • Posts: 27
Re: Patch for codeblocks 20.03 adding multi columns in memory dump
« Reply #17 on: February 15, 2021, 08:44:05 am »
I have installed cbMemoryView plugin, is it only for windows system? On debian system I rename file cbMemoryWatch_unix.cbp in cbMemoryView_unix.cbp. Changed the lines containing MemoryWatch to MemoryView and added lib aui depending. Fixed some shortcomings in the plugin, while it cannot serve as a complete replacement for memorydump. As an addition.

« Last Edit: February 15, 2021, 08:46:26 am by MicroSourceCode »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Patch for codeblocks 20.03 adding multi columns in memory dump
« Reply #18 on: February 18, 2021, 04:13:29 pm »
Something maybe off topic, but I'm interested in view the memory as an image.
I'm mainly developing image processing algorithm, such as OpenCV's cv::Mat.

I would like to view the image in the debugger. Some years ago, I use the GDB's pretty printer to fetch the debugee's memory, and construct a image.
See my project page here: https://sourceforge.net/projects/visualdebugger/

I would like find a way to directly view the memory as an image, I'm not sure GDB's CLI(command line interface) can pass image raster bytes to C::B, or maybe, we need to use some TCP connection from C::B to the debugger(or the customized python pretty printer)

Any suggestions?

Thanks.
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 oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Patch for codeblocks 20.03 adding multi columns in memory dump
« Reply #19 on: February 18, 2021, 08:51:06 pm »
You'll have to write a plugin for this or somehow expand the watches view or some other kind of view, but I doubt it will be reliable without too much effort.
Keep in mind that the current debugger plugin is going to the recycling bin, hopefully it will happen this year, but I don't promise anything. :)
(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 MicroSourceCode

  • Multiple posting newcomer
  • *
  • Posts: 27
Re: Patch for codeblocks 20.03 adding multi columns in memory dump
« Reply #20 on: February 21, 2021, 10:28:09 am »
Something maybe off topic, but I'm interested in view the memory as an image.
I'm mainly developing image processing algorithm, such as OpenCV's cv::Mat.

Is it a memory pointer? If a pointer is present then the pretty printer can handle this memory. TCP connection will be significantly slower, do you want to process the data stream through wxwidget to display it?

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Patch for codeblocks 20.03 adding multi columns in memory dump
« Reply #21 on: February 22, 2021, 05:08:03 am »
Something maybe off topic, but I'm interested in view the memory as an image.
I'm mainly developing image processing algorithm, such as OpenCV's cv::Mat.

Is it a memory pointer? If a pointer is present then the pretty printer can handle this memory. TCP connection will be significantly slower, do you want to process the data stream through wxwidget to display it?

No, it is not a memory pointer, it is just a normal variable. Let me explain below:

There are mainly 3 parts, each part has a seperate process.

The first part is the debugee, where the cv::Mat resides. It is just a normal variable which has the type cv::Mat.
The second part is the GDB, where I can run the Python pretty printer to fetch the debugee's memory, the memory is usually huge, for example, a 1000*1000 pixel image, one byte for each pixel, then it is 1M bytes.
The third part is the Code::Blocks or the debugger plugin, which communicates with GDB by pipes(stderr, stdout, stdin).

I would like the show the image in the debugger plugin, so I need to find a way to pass the huge memory(1M bytes in my example) from the GDB to Code::Blocks. I'm not sure it is OK to through the command pipes, I think this will pollute the norman command line based communication. So, I would find a way such as using TCP.

BTW: the reason I would like to show the image in Code::Blocks' process is that I can show the image in GDB's process(by using the Python's GUI), if GDB is running, those GUI will hang.
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 MicroSourceCode

  • Multiple posting newcomer
  • *
  • Posts: 27
Re: Patch for codeblocks 20.03 adding multi columns in memory dump
« Reply #22 on: February 22, 2021, 12:46:56 pm »
Quite intricate. Don't want to use BlueHazzard's memory interface? Take the memory you want, then do something like this:

Mat image (1920, 1080, CV_8UC3);
typedef cv :: Point3_ <uint8_t> Pixel;
// first. raw pointer access.
for (int r = 0; r <image.rows; ++ r) {
    Pixel * ptr = image.ptr <Pixel> (r, 0);
    const Pixel * ptr_end = ptr + image.cols;
    for (; ptr! = ptr_end; ++ ptr) {
        ptr->x = 255;
    }

and convert cv::Mat to wxBitmap for output to window. This is simplified, the data can be compressed.

https://github.com/PBfordev/wxopencvtest
« Last Edit: February 22, 2021, 01:53:31 pm by MicroSourceCode »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Patch for codeblocks 20.03 adding multi columns in memory dump
« Reply #23 on: February 22, 2021, 03:37:29 pm »
Quite intricate. Don't want to use BlueHazzard's memory interface? Take the memory you want, then do something like this:

If I understand correctly, BlueHazzard's memory interface just use the GDB's memory dump command Memory (Debugging with GDB).

Normally, a cv::Mat has a header part and follows the GRAY/RGB raster color byte array. I can find the start address of the raster byte array, and construct a wxBitmap.

The only concern is that I'm not sure if dump a huge memory(for example, a 5M byte memory) is possible. Will it cause slow down of GDB pipes?
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 oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Patch for codeblocks 20.03 adding multi columns in memory dump
« Reply #24 on: February 22, 2021, 06:08:29 pm »
It will be slow, because of the slow communication (mostly on the C::B site) between C::B and gdb.
But the biggest problem is that you don't have an easy way to show an image in C::B from the debugger.
You could probably do this in gdb-python-only by making a command which stores an image on disc every time you execute it. After that you could use your favourite image viewer to inspect it.
(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 MicroSourceCode

  • Multiple posting newcomer
  • *
  • Posts: 27
Re: Patch for codeblocks 20.03 adding multi columns in memory dump
« Reply #25 on: February 24, 2021, 02:06:05 pm »
How slow, only an experiment can show, for example, copying 10 mb of any data.
At the moment, the start of displaying an image is possible only by modifying the program code itself. This is not particularly difficult, you need to write a procedure that receives input and output from the debugger and runs the callback function, as an example, you can see how this is done for the CPU Registers dialog and other debugger windows.

Ideally, the codeblocks program should have a generic approach for doing this, providing the ability to custom filter input and output from the debugger for plugins.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Patch for codeblocks 20.03 adding multi columns in memory dump
« Reply #26 on: February 24, 2021, 07:26:32 pm »
How slow, only an experiment can show, for example, copying 10 mb of any data.
I know it is slow. Especially if gdb prints the data on multiple rows as it likes to do. :)
Also I know why it happens. :)
(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 MicroSourceCode

  • Multiple posting newcomer
  • *
  • Posts: 27
Re: Patch for codeblocks 20.03 adding multi columns in memory dump
« Reply #27 on: February 26, 2021, 08:25:47 am »
I changed the behavior of my patch, now the memory dump list remembers its previous position, and returns to this position during step-by-step debugging. Here is the code for wxTextCtrl:

int w, h, clientHeight;
       m_pText->GetClientSize(&w, &h);

       clientHeight = (h + (h % m_pText->GetCharHeight())) / m_pText->GetCharHeight();
       unsigned maxScrollPosition = m_pText->GetScrollRange(wxVERTICAL)- h + 2;
       unsigned position = m_pText->GetScrollPos(wxVERTICAL);

       if ( position < maxScrollPosition )
       {
           int result = position / m_pText->GetCharHeight() + clientHeight;
                          int parttext, col;
                          parttext = m_pText->GetLineLength(m_pText->GetNumberOfLines() / 2) + 1;

                          col = result < m_result ? m_result - result : result - m_result;

                          if  ( col > 2 )
                               m_result = result;

     m_pText->ShowPosition(m_result * parttext - parttext + 1);

The code works correctly on my machine, if the font of the list is 10 pt or more, if less then it can be easily adapted.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Patch for codeblocks 20.03 adding multi columns in memory dump
« Reply #28 on: February 26, 2021, 03:49:56 pm »
Some more information, there is a project: OpenImageDebugger, which can show in-memory OpenCV image or Eigen matrix, I see it has some code to run a TCP server, it's GUI is based on QT.

Another Visual studio visual debugger plugin awulkiew/graphical-debugging: GraphicalDebugging extension for Visual Studio, which can show many in memory data(such as int array, matrix)
« Last Edit: February 26, 2021, 03:52:56 pm 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 MicroSourceCode

  • Multiple posting newcomer
  • *
  • Posts: 27
Re: Patch for codeblocks 20.03 adding multi columns in memory dump
« Reply #29 on: February 26, 2021, 06:04:49 pm »
OpenImageDebugger uses the same technology as the pretty printer, you need to define the variable for watch manually, or make an interface for this. As for the visual debugger plugin, I can't say anything.