MATLAB: Access gdb variables from matlab

gdb debug maltabMATLAB

Dear community, does anyone know how to access gdb (gnu debugger) memory space from matlab, while debugging external C/C++ code? Best Regards Mikhail

Best Answer

I found my way of interacting with GDB using tcpip, although it requires a bit of setup.
As I already said, gdb has a python interface. The way to proceed is to create tcpip tunnel to the (gdb) command line and then everything else is easy. So I wrote a small script that does that job (first attachment)
Instruction:
  1. Download the following python script as save it somewhere (replace extension form .m to py)
  2. create .gdbinit file in the folder of debug, where the following line is required: source path_to_the_script/py_dbg.py
  3. start debugging and at the breakpoint execute the loaded function: python py_dbg(34555). Instead of that number can be any port you with to use. From that moment on, it is possible to access the gdb throug telnet.
From the Matlab side I wrote a function that explicitly extracts the matrix using this inteface. As I currently work with Armadillo objects, the second attached function is capable of correctly determining the size of the matrix and directly exporting it from gdb to Matlab.
for example, if the variable of interest is called temp, the following command would do the job:
port_no = 34555;
cpp_matrix = get_arma_val_gdb('temp',port_no)
I hope that can help someone. Of course, if someone finds a more straightforward way of doing that, I am interested.
Regards
Mikhail