Introducing python debugger mode with PDB console

Debugger always comes handy when you are writing complex program and you get stuck with logical bug in the program. Most programs scratch their mind when tracking bug. Sometimes its easy to catch problem sometimes it takes hours to figure it out. But if you know how to use debugger you can track the problem easily and quicker.

Having said that, We are glad to announce that now you can debug python program with OnlineGDB IDE. Some of python programmer would be knowing about PDB debugger  module. We have built an easy to use web interface for debugging python program running under PDB debugger.

How to start python program in debug mode?
Goto OnlineGDB IDE. Click on “Debug” button on top bar. And there you go, it will open PDB debug console and other helping windows (e.g. call stack, local variables, breakpoints)

What can I do in debug mode?
1. Set/clear breakpoints
2. Step by step execution of program
3. See local variables
4. PDB console is available in debug mode, you can enter any pdb command in console

In this article, you can get to know more about OnlineGDB debug interface.

Here is short demo of how to run python program in debug mode.

Debugging python program with OnlineGDB
Debugging python program with OnlineGDB

Brief guide on how to use OnlineGDB debugger

If you are new to programming world, then its possible that you may not have heard of debugger. Well, in this article I will explain OnlineGDB debugger usage in brief.

  • What is Debugger?
    In general, debugger is utility that runs target program in controlled environment where you can control execution of program and see the state of program when program is paused.
    GDB is such debugger, which is used to debug C/C++ programs.
    OnlineGDB provides an interface to use GDB in cloud environment from your browser.
  • How can I control execution of program?
    We can tell debugger when to pause a program by setting breakpoints.
    To set a breakpoint, click on blank area seen on left side of line number in editor. When you click it, it should display red circle; which means breakpoint is set on that line number. Here is image of how it looks like.

Clicking here will set breakpoint on given line number

You can set breakpoint via GDB console as well, more details you can find on this article.

Once you set breakpoint, when you start program in debug mode, it will pause execution when program reaches the line where breakpoint is set.

Breakpoint on line number 12 is hit.Program paused here.

Now we can use stepping commands to execute program line by line.

stepping commands

1. continue – Resume program execution until next breakpoint is reached
2. step into – Execute program line by line stepping into function
3. step over – Execute program line by line but don’t go inside function call
4. step out – Resume program execution until current function is finished

  • What can I see when program is paused?
    You can see call stack and values of local variables of current function.call stack shows you chain of function calls. As seen in below image, “main” function is calling function “factorial” and “factorial” is calling function “multiply”.
    call stack window

Local variables window shows you values of local variables of current function. As shown in image below, value of “fact” is 1, “i” is 1.
local variables window

Here is single image depicting usage of OnlineGDB debugger.
online gdb debugger usage

Now we have control and eye on program execution, so we can inspect program execution flow. Breakpoints, stepping commands and variables displays are basic feature of debugger. In future, I will post more features helpful for debugging.

Introducing multifile project

We listened to our users those who wanted to run multifile C++ projects and here we are with support of multifile project. Now you can create multiple file for single project and can run as a single project.

You can create new file either by pressing “Ctrl + M” or “New file” button from control-bar on top.

Here is a sample multifile C++ project.
https://www.onlinegdb.com/BkcHxB0QZ

Introducing runnable c/c++ code snippets

We are excited to introduce runnable c/c++ code snippets. Now you can embed code snippets which can be executed from your website/blog. Here is live example of embded runnable code snippet.

 

Below are steps to embed runnable code snippets to your own website.

  1. Goto onlinegdb.com
  2. Write and test your code
  3. Click “Share” button
  4. Copy “Embed Code” link, which would look like code below.
    <script src="//onlinegdb.com/embed/js/B1X6-oL-W"></script>
  5. Paste it in your article/page of your website where you want to display runnable code.Thats it. Now your readers can run your code snippets from your website.