Showing posts with label code::blocks. Show all posts
Showing posts with label code::blocks. Show all posts

Thursday, February 14, 2013

Debugging apps that use OSS (Ubuntu)

There are still a few legacy applications out there that rely on OSS for the sound system, and on many distributions such as Ubuntu, these programs can be invoked through the "padsp" utility to provide the needed functionality. But what do you do if you want to debug the program in gdb?

Fortunately, the "padsp" functionality can be obtained without actually invoking padsp, by providing the application with one environment setting: "LD_PRELOAD=/usr/lib/i386-linux-gnu/pulseaudio/libpulsedsp.so".

The exact path of the library may be different on your system. This same environment value can specified in gdb with the "set env" directive. What is even more useful is that it can be specified in the command line to gdb, using the gdb argument "-ex", e.g. '-ex "set env BLAH=blurb"' etc.

This becomes very useful in an IDE such as Code:Blocks, where arbitrary command line options to gdb can be specified in the "Settings:Debugger" dialog. Simply paste the entire construct into the "Argument" text box (note the double quotes):

-ex "set env LD_PRELOAD=/usr/lib/i386-linux-gnu/pulseaudio/libpulsedsp.so"

That's all folks!

Friday, April 1, 2011

Code::Blocks Setup

I am a big fan of Code::Blocks IDE, but had only discovered it about a year ago when I started messing around with MAME again, and was looking for a modern GUI front-end for the GNU debugger.

CodeBlocks is an IDE available for Windoze, *NIX, or MAC and released under GPL3. It apparently can support a bunch of different development environments but I have only used it with GNU'ish tool chains, particularly gcc on Linux or MingGW-gcc on WinXP.

CB has its own project manager for building and debugging - however, it can also launch builds which are handled by an external makefile. I chose the latter approach to get started quickly with Mame (it is not a trivial build to setup!) and have continued this way since. In the steps below I will go through the basic setup of the tools and the execution of a command line build, and then proceed to using CodeBlocks to build and debug with gdb.


Outline...
Downloads:
MinGW binary (Mame tools release).
Mame136 Source.
Command line build: follow instructions to do it the easy way.
(Note: I use the Cygwin shell, but need to add the MinGW installed PATH to my environment in order to call MinGW gcc and not the Cygwin gcc. I also include the path to the libexec, but I don't recall the exact reason or reference for doing so... but it works!). However, I don't care to make this a permanent environment change so I just put the following in a script which I "source" (dot operator) into my currently running shell instance:

export PATH=/cygdrive/c/MinGW/bin/:/cygdrive/c/MinGW/libexec/gcc/i686-w64-mingw32/4.4.3/:$PATHAt this point, it should be possible to build Mame from the command line to prove that the tool chain works. DEBUG turns on the internal Mame debug console, and Symbols basically enables the -g option to gcc to enable generation of the symbol table for gdb:
make DEBUG=y SYMBOLS=y emulator

Another useful option is to build the "tiny" configuration, which enables just a handful of drivers and significantly reduces the size of the executable:

make SUBTARGET=tiny DEBUG=y SYMBOLS=y emulator

I may eventually get around to describing the setup for a "tiny" build.
CodeBlocks setup:
Go to tools setup, where you can create a new toolchain configuration, or use, modify, or copy one of the many existing ones. For Windoze/MingGW, I chose to modify the existing "GNU GCC Compiler" tool profile, and simply to change the path to point to my installed MinGW.

Under "Settings/Compiler and Debugger/" and "Toolchain executables" tab:
Set the compilers installation directory to that containing the "bin" of the installed MinGW tool chain (mine lives in c:\MinGW).

The rest of the build configuration is setup by the project file:
Setup name of external makefile to call.
Set name of executable.
Set Build options Make commands.


In case of problems, there may be some helpful hints in this article.

This article may take a few editing sessions to complete so stay tuned...