Home > linux > Debugging in Linux

Debugging in Linux

Debugging application using IDE is fast and easy, but most of the times during my professional jobs I had to debug application on some server placed on the other part of the globe. I tried to use some methods for remote debugging, but I didn’t found one that would be efficient and fast enough to work smoothly.

I am also the guy that likes to do most of the things in text console (I have something from geek:) ). In such situation I will shortly present tools that I found pretty much useful.

GDB

GNU Debugger. Probably all you who have ever done some debugging on linux know this tool. Nothing more to say, you just have to know it.

CGDB

It’s terminal application that is a little similar to vim text editor by means of display and key bindings. It’s based on gdb, but it has one feature that is really helpful for me. The main window is divided in two parts: upper and lower one. The upper one presents the source code of currently debugging application, and the lower one is just the same as the window from the gdb.

You can see current line marker (green arrow), breakpoint (line number marked in red) and source code lines before and after the current one. To switch from lower window (which is the default) to the source code window you just press ESC button. To get back to the gdb window, press “i” button (like entering insert mode in vim).

When you are in source code window, you can move the code up and down using arrows (or j and k keys like in vim). You can also search strings by typing “/”. Pressing space will create or delete breakpoint (if there was any) in the current line.

PSTACK

Prints a stack trace of running processes. This tool helped me couple of times when I had to debug multithreaded application that are already started, because it prints stack trace of each thread in the process. When an application hangs because of i.e. wrongly used locks, you can use it. It prints similar output to the gdb one (with gdb you have to attach to the currently running process and print information about threads “i th”), but is just faster to type: “pstack <pid>”.

STRACE

Traces the system calls of the program. It will help you when you are trying to find out what system calls are used by the program. I haven’t used it much but I saw when my teammate solve a very hard to find problem in a second after using it.

Advertisements
Categories: linux Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: