Source code file content

Revision: 2

» Project Revision History

» Checkout URL

web-content / trunk / docs / articles / debugging / Review_NikMolchanov / NetBeansC_C++DevelopmentPack5.5_Debugging.html

Size: 18682 bytes, 1 line
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  <meta content="text/html; charset=ISO-8859-1"
  <title>NetBeans C/C++ Development Pack 5.5. Debugging.</title>
  <meta content="Nik Molchanov" name="author">
 content="Review of NetBeans C/C++ Development Pack 5.5 debugging module."
<h1 style="text-align: left;">NetBeans C/C++ Development Pack 5.5.
<h3>Table of Contents.</h3>
<h3>&nbsp;&nbsp;&nbsp; 1. <a href="#1_Overview">Overview.</a></h3>
<h3>&nbsp;&nbsp;&nbsp; 2. <a href="#2_Breakpoints">Breakpoints.</a><br>
<h3>&nbsp;&nbsp;&nbsp; 3. <a href="#3._Call_Stack_View._">Call Stack
<h3>&nbsp;&nbsp;&nbsp; 4. <a href="#4._Locals_View._">Locals View.</a></h3>
<h3>&nbsp;&nbsp;&nbsp; 5. <a href="#5._Watches_View._">Watches View.</a></h3>
<h3>&nbsp;&nbsp;&nbsp; 6. <a href="#6._Sessions_and_Threads._">Sessions
and Threads.</a></h3>
<h3>&nbsp;&nbsp;&nbsp; 7. <a href="#7._Debugger_Console._">Debugger
<h3>&nbsp;&nbsp;&nbsp; 8. <a
 href="#8._Integration_with_NetBeans_Editor._">Integration with
NetBeans Editor.</a></h3>
<h3>&nbsp;&nbsp;&nbsp; 9. <a
 href="#9._Menu_Toolbar_Buttons_and_Hot_Keys._">Menu, Toolbar Buttons
and Hot Keys.</a><br>
<h3>&nbsp;&nbsp;&nbsp; </h3>
<h2><a name="1_Overview"></a>1. Overview.</h2>
The NetBeans C/C++ Development Pack 5.5 has a debugging module, which
is based on the <a href="">GNU
debugger "gdb"</a>. Debugger "gdb" is not bundled with the NetBeans
Development Pack, users have to install it separately. I tried several
versions, and I can say that gdb 6.5 works better on Windows than all
previous gdb versions. On Solaris and Linux gdb 6.4 works better than
all previous gdb versions. Older versions also work, but not older than
6.1, and there are some problems, that are fixed in version 6.4. I
tried to use gdb 6.5 on Linux, but found some strange problems, so I
went back to gdb 6.4.<br>
To use the NetBeans C/C++ Development Pack 5.5 on Windows, I installed
the latest <a href="">Cygwin</a> release
(1.5.22-1) with its "Devel" package, and got "GNU gdb (cygwin-special)". You can use the following
commands to verify the version of Cygwin, gcc, make and gdb:<br>
$ cygcheck -c cygwin<br>
Cygwin Package Information<br>
Version&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Status<br>
1.5.22-1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OK<br>
$ cygcheck -c gcc<br>
Cygwin Package Information<br>
Version&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Status<br>
3.4.4-1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OK<br>
$ cygcheck -c make<br>
Cygwin Package Information<br>
Version&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Status<br>
3.81-1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OK<br>
$ cygcheck -c gdb<br>
Cygwin Package Information<br>
Version&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Status<br>
20060706-2&nbsp;&nbsp;&nbsp;&nbsp; OK<br>
On Linux ("SUSE LINUX Enterprise Server 9" or "Fedora Core release 3"),
I use either "/usr/bin/gdb", which is gdb 6.1, or I use gdb 6.4, which
I downloaded from <a href=""></a>
and built myself. <br>
On Solaris I use gdb 6.4, which I downloaded from <a
 href=""></a> and
built myself. The "gdb" binaries for Solaris, such as the one available
on <a href=""></a>
(gdb 6.0), are too old to be used with the NetBeans C/C++ Development
Pack 5.5. I also tried /usr/sfw/bin/gdb on Solaris Nevada (current
Solaris release has bundled "gdb" 6.3.50), and it works very well.<br>
I think the best way to get familiar with the NetBeans C/C++
Development Pack 5.5 and its debugging module is to play with sample
projects. There are several C and C++ sample projects, in that ship
with the product: HelloApp, Quote, Args, MP, Welcome, IO. When you
create a new project, you can select any of these sample projects, and
then modify it for your needs. I will use the projects "Welcome" and
"MP" to illustrate the debugging features. A picture below shows the
project "Welcome" in debugging environment on Windows XP. You can see
"Watches" view (on left side, under "Projects" view), "Sessions" view,
"Breakpoints" view, "Call Stack" view and "Locals" view. The editor
window shows the source file with two breakpoints ("red squares" on
left side at lines 28 and 33), a pointer to the current line ("green
arrow" at line 29) and tooltip evaluation of selected expression
<img style="width: 911px; height: 748px;"
 alt="Debug Sample Project Welcome1"
 title="Debug Sample Project Welcome1"
This is not a default layout for debugging windows, but it is easy to
rearrange windows according to your preferences. To move a window you
have to click on its label, drag and drop it to a new location. If you
close any of these panels by accident, you can get it back by going to
main menu: "Window &gt; Debugging &gt; ...".<br>
<h2><a name="2_Breakpoints"></a>2. Breakpoints.</h2>
Debugger "gdb" supports many types of breakpoints, but only two types
of breakpoints are supported in this release of debugging module:<br>
  <li>Line breakpoint without condition</li>
  <li>Function breakpoint without condition</li>
It is possible to set a conditional or any other breakpoint using
direct dialog with gdb through the "<a href="#7._Debugger_Console._">GDB
Debugger Console</a>", but they are not supported by debugging module,
so they may not be handled properly. A line breakpoint can be set and
removed in the editor. Just click on a line number (or on gray area on
left edge of a line). Also a line breakpoint can be set from main menu
("Run" &gt; "New Breakpoint...") or from "Breakpoints" view.<br>
What is interesting and may be unusual (and even inconvenient in some
cases) is that all breakpoints are "<span style="font-weight: bold;">global</span>".
They are not associated with a project, or a particular binary. They
are not associated with a debugging session. They affect <span
 style="font-weight: bold;">all</span> projects, <span
 style="font-weight: bold;">all</span> binaries, <span
 style="font-weight: bold;">all</span> sessions. Once a function
breakpoint is
set on the function "main", it will apply to any project as soon as it
gets into its "main" function. Once a line breakpoint is set in a
source file, it will affect all projects that include this source file.
All actions are also "<span style="font-weight: bold;">global</span>",
i.e. they affect <span style="font-weight: bold;">all</span> projects.
A picture below shows a "Breakpoints" view with all available actions:<br>
<img style="width: 345px; height: 202px;"
 alt="Breakpoints view, available Actions" title="Breakpoints Actions"
<h2><a name="3._Call_Stack_View._"></a>3. Call Stack View.</h2>
The "Call Stack" view shows function names and their locations (source
files and line numbers):<br>
<img style="width: 605px; height: 167px;"
 alt="Call Stack view, available Actions" title="Call Stack view"
Unfortunately it does not show parameters. This is a known problem and
I hope it will be fixed in next release (<a
 href="">IZ 87053</a>).<br>
What is nice is that the "Call Stack" view allows you to make any
particular frame <span style="font-weight: bold;">current</span>.
Double click on its entry in the "Call Stack" view, and the "Editor"
will show the corresponding source file, the "Locals" view will show
the corresponding local variables, and the "Watches" view will
reevaluate the expressions according to this frame. <br>
A picture below shows a modified "Welcome" project, stopped at a
breakpoint in function "f2" (line 24). I changed the current call stack
frame to "f1" (line 31), and we can see that the "Locals" view shows
variables "m" and "n" (which belong to function "f1"), the "Watches"
view reevaluated all watches, the "Editor" window shows the source of
function "f1" and the tooltip evaluation also works in context of
function "f1":<br>
<img style="width: 909px; height: 745px;"
 alt="Call Stack, Changed current frame to 2"
 title="Call Stack, Frame 2" src="Pictures/CallStack_Frame2.JPG"><br>
<h2><a name="4._Locals_View._"></a>4. Locals View.</h2>
The "Locals" view shows structures and allows you to "chase" pointers. <br>
A picture below shows a modified "Welcome" project, stopped at
a breakpoint in function "main" (line 50). The "Locals" view shows
the structure of the variable "node" (structure _Name):<br>
<img style="width: 912px; height: 616px;"
 alt="Locals view, show structure, chase pointer"
 title="Locals view, show structure, chase pointer"
Unfortunately this feature is not very stable, and sometimes nested
fields are shown as value (not recognized as fields).<br>
<h2><a name="5._Watches_View._"></a>5. Watches View.</h2>
The "Watches" view supports expressions. User can select any expression
in the "Editor" window, click the right mouse button, select "New
Watch..." item, and a "New Watch" dialog appears with selected
<img style="width: 795px; height: 332px;"
 alt="New Watch dialog, Expression" title="New Watch dialog, Expression"
Note that when expression was selected in the "Editor" window, a
tooltip evaluation appeared. You can see it in the picture below. This
feature is very similar to a "watch". The main difference is that
"watches" are permanent, and they are shown in the "Watches" view:<br>
<img style="width: 798px; height: 483px;"
 alt="Watches view shows expressions"
 title="Watches view shows expressions"
<a name="6._Sessions_and_Threads._"></a>Unfortunately "Watches" view is
not very stable yet, and sometimes types are not shown - you can see
"null" instead of "int" on this picture.<br>
<h2>6. Sessions and Threads.</h2>
Multi session support is implemented. It means user can debug two or
more projects in parallel in the same IDE. There is a special
"Sessions" view to show which sessions are running now:<br>
<img style="width: 377px; height: 160px;"
 alt="Sessions view, available Actions"
 title="Sessions view, available Actions"
Theoretically it is possible to debug a C/C++ project and and Java
project in parallel in the same IDE, but they are using different
debugging modules, and there could be some conflicts, so I would not
recommend to do such things. Even if you debug two C/C++ projects in
parallel in the same IDE, it is a very difficult and confusing task,
because debugging windows do not show which session is current now
(only "Sessions" view shows current session).<br>
Unfortunately "Threads" view is always empty - threads are not
supported in this release. Also there is no support for multiprocessing
- if a program uses fork() to create child processes, there is no
option to debug a child process.<br>
<h2><a name="7._Debugger_Console._"></a>7. Debugger Console.</h2>
This release of debugging module has a very powerful feature - direct
dialog with "gdb" via "GDB Debugger Console". Unfortunately this
is&nbsp; "unfinished" feature, and I think a beginning user will not
want to use this window because it shows the whole dialog between the
debugging module and&nbsp; "gdb", so it is hard to find important
messages there. But for "gdb" experts this feature is priceless. At any
moment I can type in
a "gdb" command in "GDB Debugger Console", press Enter, and this
will be sent to "gdb". Obviously there is a risk that the debugging
module will not understand a reply from "gdb" caused by manually sent
command. Probably that's why this feature is hidden, and it is not easy
to enable this console. I use the following way to enable "GDB Debugger
Console": <br>
- there is a directory "etc" in NetBeans installation tree, and it
contains file "netbeans.conf"<br>
- there is a line in netbeans.conf file, which defines
&nbsp;&nbsp;&nbsp; <span style="font-weight: bold;">netbeans_default_options="-J-Xms32m
-J-Xmx128m -J-XX:PermSize=32m ..."<br>
</span>- I change the maximum memory limit (because 128 megabytes is
usually not enough), and add option to show "GDB Debugger Console":<br>
&nbsp;&nbsp;&nbsp; <span style="font-weight: bold;">netbeans_default_options="-J-Xms32m
-J-Xmx328m -J-Dgdb.console.window=true -J-XX:PermSize=32m ..."<br>
</span>This option (<span style="font-weight: bold;">-J-Dgdb.console.window=true)
</span>tells IDE to show "GDB Debugger Console" when a debugging
session starts. You can see it on the picture below. In this example I
set a conditional breakpoint at line 41 ("break if
argc&lt;3"), and the program stopped there:<br>
<img style="width: 905px; height: 583px;" alt="GDB Debugger Console"
 title="GDB Debugger Console" src="Pictures/GDB_Debugger_Console.JPG"><br>
Debugging module does not show a breakpoint icon on line 41, because I
used <a
syntax</a>, and because this breakpoint was not set from inside IDE.
But, what is good, it did not break anything, and I can continue the
debugging. NetBeans C/C++ Development Pack 5.5 debugging module is
using <a
interface</a> to communicate with debugger "gdb", so it is probably
better to type in gdb commands using GDB/MI syntax.<br>
Even if you don't want to type in gdb commands, it makes sense to have
"GDB Debugger Console" open, because in some cases it is not clear what
is going on (for example, why a "Step Over" action does not change
anything?), and in this case "GDB Debugger Console" is extremely
helpful - it shows gdb commands and replies, which makes easy to
understand the problem.<br>
Unfortunately "GDB Debugger Console" is called "Debugger Console", and
there is another "Debugger Console" window, so there could be some kind
of confusion - too many "Debugger Console" windows:<br>
<img style="width: 730px; height: 237px;"
 alt="Debugger Console (default)" title="Debugger Console (default)"
This is probably another reason why "GDB Debugger Console" is hidden.<br>
<span style="font-weight: bold;"></span><span style="font-weight: bold;"></span>
<h2><a name="8._Integration_with_NetBeans_Editor._"></a>8. Integration
with NetBeans Editor.</h2>
Integration with the NetBeans "Editor" is pretty much traditional. When
a debugging session is active, and the program is stopped, the "Editor"
  <li>&nbsp; current source file</li>
  <li>&nbsp; current line ("green arrow" and "green background")</li>
  <li>&nbsp; breakpoint annotations ("red squares" and "red background")</li>
  <li>&nbsp; call stack lines ("gray triangle" and "gray background")</li>
  <li>&nbsp; tooltip
evaluation of selected expression</li>
<img style="width: 854px; height: 407px;"
 alt="Editor, Debugging Session is active"
 title="Editor, Debugging Session is active"
If there is no debugging session, only breakpoint annotations are shown
in the "Editor".<br>
<h2><a name="9._Menu_Toolbar_Buttons_and_Hot_Keys._"></a>9. Menu,
Toolbar Buttons and Hot Keys.</h2>
<img style="width: 364px; height: 64px;" alt="Debugging Toolbar Buttons"
 title="Debugging Toolbar Buttons"
There are 11 toolbar buttons, related to debugging: <br>
  <li>Debug Main Project (F5)</li>
  <li>Attach Debugger...<br>
  <li>Finish Debugging Session (Shift+F5)<br>
  <li>Continue (Ctrl+F5)</li>
  <li>Step Over (F8)<br>
  <li>Step Into (F7)<br>
  <li>Step Out (Ctrl+F7)<br>
  <li>Run to Cursor (F4)</li>
  <li>Apply Code Changes<br>
  <li>New Watch... (Ctrl+Shift+F7)<br>
Three of them are not implemented in this release:<br>
  <li>Attach Debugger... </li>
  <li>Run to Cursor </li>
  <li>Apply Code Changes</li>
They are not removed from the toolbar, because they are used in Java
debugging. <br>
Also there are some problems with "Pause" on Cygwin/Windows. These
problems do not affect Linux or Solaris. To implement this
feature on Windows in Cygwin environment a dynamic library ("cnd.dll")
is used, which implements a
signal handler ("_CndSigHandler" function). When debugging is starting,
this signal handler is instrumented into the program (using LD_PRELOAD
method). Then the program is stopped in "main" function and this signal
handler is activated. After that the execution begins, and if user
pressed "Pause" button, a signal (SIGTSTP) is sent to the program.
Signal handler catches this signal, and execution is stopped at a
special breakpoint. After that a few single steps are used to get back
to user's sources. And in some cases this algorithm does not work -
"gdb" cannot get back to the user's sources, and "Call Stack" view
shows that the program is stopped in "_CndSigHandler" function. This is
a known problem and
I hope it will be fixed in next release (<a
 href="">IZ 90120</a>).<br>
<hr style="width: 100%; height: 2px;"><br>
<h4>Nikolay Molchanov</h4>
December 2006<br>

Project Features

About this Project

CND was started in November 2009, is owned by DimaZh, and has 197 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20160708.bf2ac18). © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
Please Confirm