Author Topic: debugging an R language dll  (Read 3353 times)

Offline Andre_Mikulec

  • Single posting newcomer
  • *
  • Posts: 8
debugging an R language dll
« on: February 11, 2019, 10:32:05 am »
Hi,

I am trying to use code::blocks Debugger to debug an R language dll.

The process is unusual. But (below) the process is correct.

I managed to configure the debugger to give me this line.

Starting debugger: W:\gdb2018-07-25-bundle-python27\bin\gdb.exe -nx -fullname -quiet W:\R-3.5._\App\R-Portable\bin\i386\Rgui.exe  -args W:/R-3.5._/codeblocksMeta/CodeBlocks/gdbCgen/bin/Debug/gdbCgen.exe

In the gdb debugger, when I run. I get this.

```
run
No executable specified, use `target exec'.
Starting program: 
```
From Windows command line testing, I know need to remove "-args W:/R-3.5._/codeblocksMeta/CodeBlocks/gdbCgen/bin/Debug/gdbCgen.exe
".

Therefore, only left would be
```
W:\gdb2018-07-25-bundle-python27\bin\gdb.exe -nx -fullname -quiet W:\R-3.5._\App\R-Portable\bin\i386\Rgui.exe
```
This is correct and by design. ( There is no gdbCgen.exe: never was and never will be. )

How do I remove the extra?

If the removal can not easily be done, then where in the source code, can I make this modification.

Note: Currently,  I use debugbreak.exe to do the breaking (CTRL+C).

Thanks,

Andre
« Last Edit: February 11, 2019, 11:40:48 am by Andre_Mikulec »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: debugging an R language dll
« Reply #1 on: February 11, 2019, 02:09:27 pm »
Quote
Starting debugger: W:\gdb2018-07-25-bundle-python27\bin\gdb.exe -nx -fullname -quiet W:\R-3.5._\App\R-Portable\bin\i386\Rgui.exe  -args W:/R-3.5._/codeblocksMeta/CodeBlocks/gdbCgen/bin/Debug/gdbCgen.exe

I think you use the wrong command.

here, you want to use GDB.exe to debug the "Rgui.exe". "gdbCgen.exe" is an argument passed to the start command of the "Rgui.exe".

Normally, you try first try this in Windows Command line, such as:
Code
gdb.exe -nx -fullname -quiet  -args W:\R-3.5._\App\R-Portable\bin\i386\Rgui.exe

After that, you can set the args:
Code
set args W:/R-3.5._/codeblocksMeta/CodeBlocks/gdbCgen/bin/Debug/gdbCgen.exe

Finally, you can type:
Code
run
To start the debugging.

Under C::B's debugger plugin, you use the same way, the command line arguments are set in "Menu->Project->Set program argument..."

EDIT: Please enable the "Full Debug log" in your C::B's debugger plugin settings to show the full debug log.
« Last Edit: February 11, 2019, 02:11:27 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 Andre_Mikulec

  • Single posting newcomer
  • *
  • Posts: 8
Re: debugging an R language dll
« Reply #2 on: February 11, 2019, 04:23:44 pm »
ollydbg,

Thanks.

My build processes has no compiler and no linker.

I just want to use  the code::blocks GUI Debugger.
I am not really debugging Rgui.exe. I am debugging a .dll that I will load later (example not shown).

Debugging is also composed of a python-gdb debugger (example shown below) and
a pretty-printing .py script that expands SEXP expressions (not shown in the example above).

The debugging process starts with debugging the Rgui.exe.  But I am not really debugging it.
I am  running RGui, then loading a pre-compiled special debuggable dll: . dyn.load("foo.dll").
Then I use an RGui menu command to break to gdb.  In gdb I set a breakpoint at foo:3.
Next, I break out of gdb using debugbreak.exe,
Back inn RGui, I run the dll using .C("foo", parameters ).

This
"
W:/R-3.5._/codeblocksMeta/CodeBlocks/gdbCgen/bin/Debug/gdbCgen.exe
"
is automatically filled in by the code::blocks Debugging: gdbCgen does not exist.

How do I  stop code::blocks from filing this in?

This is preventing me from running the debugger using the way I want it to run it.

Thanks,
Andre

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: debugging an R language dll
« Reply #3 on: February 11, 2019, 06:45:36 pm »
Make a dummy, probably custom makefile project and set the output to be you're executable. Or find a way to set the host executable. See Project -> Set program's arguments.

If this is too complex you can always do Debug -> Attach.
(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 Andre_Mikulec

  • Single posting newcomer
  • *
  • Posts: 8
Re: debugging an R language dll
« Reply #4 on: February 11, 2019, 10:14:13 pm »
ollydbg and oBFusCATed,

O.K.thanks. The gist of my question was "is there" an easy way.

I understand that the Debugger is hard coded to accept an XYZ.exe
(and I have to provide some 'real' XYZ.exe)

I will try those solutions.

Thanks,
Andre

Offline Andre_Mikulec

  • Single posting newcomer
  • *
  • Posts: 8
Re: debugging an R language dll
« Reply #5 on: February 12, 2019, 10:05:14 am »
Thanks,

In code::bocks, I ended up doing:

Settings->Debugger-> Common-> [ ] Auto-build project if it is not up-to-date
Settings->Debugger->GDB/CDB debugger->Default-> [ ] Do *not* run the debugger
Projects->MyProject->Build targets->Output filename: W:\R-3.5._\App\R-Portable\bin\i386\Rgui.exe

Debug->Start/Continue
run

Following the R part:
8.4 How do I debug code that I have compiled and dyn.load-ed?
https://cran.r-project.org/bin/windows/base/rw-FAQ.html

the rest happened as I described earlier, except,
I ended up *not having to use* debugbreak.exe.
"RGui->Misc-> Break to Debugger" worked just like it should.

Also, (the GOAL), the usage of code::block's Debugger GUI worked out exactly like it should.


Offline Andre_Mikulec

  • Single posting newcomer
  • *
  • Posts: 8
Re: debugging an R language dll
« Reply #6 on: February 12, 2019, 10:41:06 am »
Note:
I am working on windows. When I tried Rterm.exe in place of Rgui.exe,  at the Rterm.exe command prompt, I pressed CTRL+C, and control returned to gdb (in code::blocks).  So the control-switching works just like it works for Linux/UNIX people working with gdb (and not windows people where this control switching is expected to 'not work').  I also tried (the goal), breakpoints, and debugging, and that works.

I am not sure who gets the credit for this.
Thanks, R language programmers.   
Thanks "python enabled gdb 8.2" programmers.

I am using R 3.5.2 on Windows 10 Professional on Dell Intel hardware purchased in late 2016.


« Last Edit: February 12, 2019, 06:07:57 pm by Andre_Mikulec »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5910
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: debugging an R language dll
« Reply #7 on: February 12, 2019, 03:59:37 pm »
Nice to here you solved the problem!

BTW: if you use the GDB from this link: [OT] unofficial MinGW GDB gdb with python released(2018-07-25), then it's me(I build this package).  ;)
« Last Edit: February 12, 2019, 04:20:29 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 Andre_Mikulec

  • Single posting newcomer
  • *
  • Posts: 8
Re: debugging an R language dll
« Reply #8 on: February 12, 2019, 05:46:07 pm »
ollydbg,

Yes, I do use.
[OT] unofficial MinGW GDB gdb with python released(2018-07-25)

It is awesome.

Thanks.