We know there are many commercial tools to debug memory on Solaris systems as Dynamic Suite and Purify. But I prefer to use open source tools always it is possible.

Well, Linux has many open source tools and the best in my opinion is Valgrind, but Valgrind will not be ported to sparc architecture as well to (open)solaris. Then, what tool I should use ?

(Open)Solaris has useful tools to debug memory, the most known is DTrace, but I’ll talk of two important and easiest tools to use: libumem and watchmalloc (equivalent to MALLOC_CHECK from linux).

Using libumem

It’s not need to recompile your application. The library is loaded dynamically by LD_PRELOAD environment variable.

  • Prepare your environment
$ setenv UMEM_DEBUG default
$ setenv UMEM_LOGGING transaction
$ setenv LD_PRELOAD libumem.so.1
  • Run the application normally
 $ ./myapp
  • After the program has passed by all fluxes, generate a core to analyze with mdb
$ gcore `pgrep myapp`
$ mdb myapp core.pid
  • With mdb opened, just run a simple command (findleaks):
> ::findleaks -dvf
CACHE     LEAKED   BUFCTL CALLER
0014f12f       1 00067000 libumem.so.1`malloc+0x0
----------------------------------------------------------------------
 Total       1 buffer, 48 bytes

Using watchmalloc

Watchmalloc is the linux equivalent to MALLOC_CHECK. The use is most simple than libumem. See it:

  • Prepare your environment
$ setenv MALLOC_DEBUG=WATCH,RW
$ setenv LD_PRELOAD watchmalloc.so.1
  • Run the application normally
$ ./myapp
  • When a leakage happens the program will generate a core dumped and will be possibly to analyze with gdb.

bug

Brazilian Planet OpenSolaris

February 18, 2009

Born Planet OpenSolaris in PT_BR !!!

Planet OpenSolaris BR

Planet OpenSolaris BR

In this week I had to write a little code to remove all IPC Shared Memory segments that were created by one process.

I had already done it on Linux and *BSD systems, but never on (Open)Solaris. Then, I tried to search (googling) some method to do it but without successful.

Linux and *BSD’s have a syscall named sysctl() to interface it, but sunos kernel has not.

Well, after some minutes breaking my brain, I discover a syscall easiest to use than sysctl…look the code below:

#include <stdlib.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
void show_shm (void)
{
  int i;
  int     *buf;
  uint_t  nids;
  uint_t  pnids;
  for (;;)
  {
    if (shmids(buf, nids, &pnids) != 0)
      exit(1);
    if (pnids <= nids)
      break;
    buf = realloc(buf, (nids = pnids) * sizeof (int));
  }
  for (i = 0; i < pnids; i++)
    printf ("%dn", buf[i]);
}

link2_os_blk_125

When I installed OpenSolaris 2008.05 in my laptop (Sony Vaio), the operating system does not recognized my ethernet card (marvel yukon), but identified my wireless NIC.

I don’t use ethernet card frequently because I have a Wireless Access Point. But, some days ago I had to enable my Marvel Yukon.

Let’s see how did I do this:

By default, snv_86 build does not come with the Marvel Yukon driver enabled in the kernel. But you can download it at:

http://homepage2.nifty.com/mrym3/taiyodo/myk-2.6.5.tar.gz

Done that, I take these steps:

  1. tar -zxvf myk-2.6.5.tar.gz
  2. cd myk-2.6.5
  3. rm -Rf obj Makefile
  4. ln -s Makefile.i386_gcc Makefile
  5. ln -s i386 obj
  6. export PATH=/usr/ccs/bin:$PATH
  7. which gcc (/usr/ccs/bin/gcc expected)
  8. which make (/usr/ccs/bin/make expected)
  9. pfexec make install
  10. pfexec ./adddrv.sh (should says ok!)
  11. ifconfig myk0 plumb
  12. ifconfig -a (wow ! I see my ethernet card!!!  ;) )

PS: Before try my tips, please, read the installation document in tarball ’cause you can have to do different steps.

Links:

http://homepage2.nifty.com/mrym3/taiyodo/eng/

PostgreSQL for Solaris

September 27, 2008

Oh, this weekend is happening the PostgreSQL Conference 2008 in Brazil. It’s a great opportunity to post in my blog something related with it. As Sun Microsystems will be a sponsor of the Conference, I will talk a little about PostgreSQL for Solaris.

First, a bad notice that Josh Berkus is no longer in Sun. =(

Second…

Well, I’m not a OpenSolaris expert, but I like it. Always I have to setup or make PostgreSQL tricks on Sun Operating Systems (SunOS/Solaris or OpenSolaris) I consult some useful links:

PostgreSQL for Solaris

PostgreSQL for Solaris

Go PostgreSQL, Go !!!

Art and Open Source

August 17, 2008

Today, I was reading tools that need to be converted or to be packaged into Solaris/OpenSolaris. One of the tools most awaited is Inkscape.

Well, now, I’m trying to compile Inkscape (svn version [1]) into my OpenSolaris. I thought to follow this tutorial, but it must be overcome and it’d take much of my time. =D

If I can compile and ran Inkscape binaries, I’ll notice in my blog and I’ll upload the package to OpenSolaris repositories.

Remember that Open Source is not only coding, visit this site and give a change to yourself: http://codefree-mag.org/

Think, breath and contribute in different ways and how you can to open source projects. We need you.

[1]https://inkscape.svn.sourceforge.net/svnroot/inkscape/inkscape/trunk

That’s all folks. ;)

Updating OpenSolaris

August 15, 2008

Hello all,

in my last post I have wrote about Firefox 3 on OpenSolaris. Björn corrected me about it. Firefox3 is already  in snv_95 image.

Currently, OpenSolaris 2008.05 livecd has been with environment snv86. So, let’s learn how to update your OpenSolaris image.

  • Update package list
pkg refresh
  • Upgrade your environment: it will create a new image to preserve and secure your current image
pkg image-update
  • After some cups of coffee (a big and boring download :/), you will see this message:
A clone of opensolaris exists and has been updated and activated.
On next boot the Boot Environment opensolaris-1 will be mounted on '/'.
Reboot when ready to switch to this updated BE.
  • To see your environments, just do it:
beadm list
  • Now, let’s notice the grub about the changes:
pfexec mount -F zfs rpool/ROOT/opensolaris-1 /mnt
pfexec /mnt/boot/solaris/bin/update_grub -R /mnt/
  • Reboot and choice “Solaris 2008.11 snv_95 X86

:)

OpenSolaris

August 14, 2008

Finally, I’ve decide to install OpenSolaris on my Sony Vaio laptop. It functions perfectly…video, audio, flashplayer and wireless.

I installed the OpenSolaris 2008.05 in a 50GB partition. Then, I think I have enough space to make my experiences. ;)

And now, I’ll install Firefox3 on my OpenSolaris box. This package can be find here.