Page 1 of 1

Help! Using CodeLite like gdb, to debug a DLL running in R?

Posted: Wed Aug 08, 2012 4:13 am
by Timojito
Codelite v4.0.5589 on Windows (not self-built, I just downloaded the exe)

Am looking for help in recreating in CodeLite something that I can currently do in gdb - basically, linking gdb with an R session (R as in the statistical programming language), and then stepping through the code of an existing dll, using the inputs defined in the R session.

To explain further, I have a cpp source file and its associated dll, which has been compiled using g++ with debugging enabled (note: this was done within an adapted version of cxxfunction, which is part of the Rcpp package in R, but the main thing is that I have a .cpp file and a .dll file and all the debugging stuff is enabled).

Now, I've found I can debug the dll (let's call it example.dll) line by line using gdb be doing the following steps:

1. In a command prompt, change directory to the location of the dll (e.g. C:/mydll/)... note the cpp source example.cpp is also in this folder
2. Then enter "gdb Rgui.exe" (which starts up a gdb session) and then "run" (which starts up R in the background)
3. Load up example.dll into R using the command "dyn.load('C:/mydll/example.dll')"
4. Break back to the gdb (there is an option in the R pulldown menus to do this)
5. Set a breakpoint in gdb by entering "b example"
6. Enter "c" (for continue) in gdb, which passes control back to R
7. Call the dll within R using a command like ".Call("example",3)" where 3 is the input value to the dll
8. The dll automatically pauses and control passes to gdb, where you can view the code line by line, interrogate variables, etc

As you can see, quite a few steps, but nothing very difficult - the gdb session is able to communicate with R and whatever inputs are put in the ".Call", the dll freezes and gdb takes control.

I'd like to recreate this behaviour using CodeLite as by all accounts this would be a much more friendly debugging environment.

I think it could be something to do with "Attach to process" but I'm really confused. Please help - any pointers would be very much appreciated! :)

Cheers
Tim

Re: Help! Using CodeLite like gdb, to debug a DLL running in R?

Posted: Wed Aug 08, 2012 7:45 am
by eranif
If you have a codelite project, right click it and select the 'Debugger' tab, where you have place to put all the commands you want to on startup (e.g dyn.load('C:/mydll/example.dll'))]

You can also use the 'Quick Debug' option (from the main menu: Debug -> Quick Debug)

Eran

Re: Help! Using CodeLite like gdb, to debug a DLL running in R?

Posted: Thu Aug 09, 2012 2:41 am
by Timojito
Hey

Thanks for the reply. I have nothing in a Codelite project, but as described I already have a compiled dll (and its cpp source) that I want to interact with.

What should I do to set this up? The dll compilation is taking place via a command in R at the moment which might be difficult to do another way, so I'm really looking for a way to get Codelite to interact with R and the exisiting dll to aid debugging, rather than using it to do the compilation. Can anyone help me with the steps to do this?

Cheers,
Tim

Re: Help! Using CodeLite like gdb, to debug a DLL running in R?

Posted: Thu Aug 09, 2012 10:17 am
by eranif
Like I said: you need a codelite project.
- Create an empty project
- Open the project settings and under the 'General -> Program to Run / Debug' select your executable that you wish to debug
- To start debugging simply hit F5 (this is equal to: gdb <exe> -> continue)
- To place a breakpoints, you can either open a source file and click on the left margin where you want to breakpoint
- OR from the 'Debugger View' select the 'Breakpoints' tab and click 'Add..'

Eran