Source code file content

Revision: 2

import
» 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">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
 http-equiv="content-type">
  <title>NetBeans C/C++ Development Pack 5.5. Debugging.</title>
  <meta content="Nik Molchanov" name="author">
  <meta
 content="Review of NetBeans C/C++ Development Pack 5.5 debugging module."
 name="description">
</head>
<body>
<h1 style="text-align: left;">NetBeans C/C++ Development Pack 5.5.
Debugging.</h1>
<br>
<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>
<h3>&nbsp;&nbsp;&nbsp; 3. <a href="#3._Call_Stack_View._">Call Stack
View.</a></h3>
<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
Console.</a></h3>
<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>
<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="http://www.gnu.org/software/gdb/">GNU
debugger "gdb"</a>. Debugger "gdb" is not bundled with the NetBeans
C/C++
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>
<br>
To use the NetBeans C/C++ Development Pack 5.5 on Windows, I installed
the latest <a href="http://www.cygwin.com/">Cygwin</a> release
(1.5.22-1) with its "Devel" package, and got "GNU gdb
6.5.50.20060706-cvs (cygwin-special)". You can use the following
commands to verify the version of Cygwin, gcc, make and gdb:<br>
<br>
$ cygcheck -c cygwin<br>
Cygwin Package Information<br>
Package&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Version&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Status<br>
cygwin&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
1.5.22-1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OK<br>
<br>
$ cygcheck -c gcc<br>
Cygwin Package Information<br>
Package&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Version&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Status<br>
gcc&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
3.4.4-1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OK<br>
<br>
$ cygcheck -c make<br>
Cygwin Package Information<br>
Package&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Version&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Status<br>
make&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
3.81-1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OK<br>
<br>
$ cygcheck -c gdb<br>
Cygwin Package Information<br>
Package&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Version&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Status<br>
gdb&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
20060706-2&nbsp;&nbsp;&nbsp;&nbsp; OK<br>
<br>
<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="http://ftp.gnu.org/gnu/gdb/">http://ftp.gnu.org/gnu/gdb/</a>
and built myself. <br>
<br>
On Solaris I use gdb 6.4, which I downloaded from <a
 href="http://ftp.gnu.org/gnu/gdb/">http://ftp.gnu.org/gnu/gdb/</a> and
built myself. The "gdb" binaries for Solaris, such as the one available
on <a href="http://www.sunfreeware.com/programlistsparc8.html">http://www.sunfreeware.com/programlistsparc8.html</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>
<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
("argv[i]").<br>
<br>
<img style="width: 911px; height: 748px;"
 alt="Debug Sample Project Welcome1"
 title="Debug Sample Project Welcome1"
 src="Pictures/Debug_Welcome_1.JPG"><br>
<br>
<br>
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>
<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>
<ul>
  <li>Line breakpoint without condition</li>
  <li>Function breakpoint without condition</li>
</ul>
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>
<br>
<img style="width: 345px; height: 202px;"
 alt="Breakpoints view, available Actions" title="Breakpoints Actions"
 src="Pictures/Breakpoints_Actions.JPG"><br>
<br>
<br>
<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>
<br>
<img style="width: 605px; height: 167px;"
 alt="Call Stack view, available Actions" title="Call Stack view"
 src="Pictures/CallStack_Actions.JPG"><br>
<br>
Unfortunately it does not show parameters. This is a known problem and
I hope it will be fixed in next release (<a
 href="http://cnd.netbeans.org/issues/show_bug.cgi?id=87053">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>
<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>
<br>
<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>
<br>
<img style="width: 912px; height: 616px;"
 alt="Locals view, show structure, chase pointer"
 title="Locals view, show structure, chase pointer"
 src="Pictures/Locals_Structures_Pointers.JPG"><br>
<br>
Unfortunately this feature is not very stable, and sometimes nested
fields are shown as value (not recognized as fields).<br>
<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
expression:<br>
<br>
<img style="width: 795px; height: 332px;"
 alt="New Watch dialog, Expression" title="New Watch dialog, Expression"
 src="Pictures/NewWatch_Expression.JPG"><br>
<br>
<br>
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>
<br>
<br>
<img style="width: 798px; height: 483px;"
 alt="Watches view shows expressions"
 title="Watches view shows expressions"
 src="Pictures/Watches_Expressions.JPG"><br>
<br>
<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>
<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>
<br>
<img style="width: 377px; height: 160px;"
 alt="Sessions view, available Actions"
 title="Sessions view, available Actions"
 src="Pictures/Sessions_Actions.JPG"><br>
<br>
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>
<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
command
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
"netbeans_default_options":<br>
&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>
<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 mp.cc:41 if
argc&lt;3"), and the program stopped there:<br>
<br>
<img style="width: 905px; height: 583px;" alt="GDB Debugger Console"
 title="GDB Debugger Console" src="Pictures/GDB_Debugger_Console.JPG"><br>
<br>
Debugging module does not show a breakpoint icon on line 41, because I
used <a
 href="http://sources.redhat.com/gdb/current/onlinedocs/gdb_toc.html">CLI
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
 href="http://sources.redhat.com/gdb/current/onlinedocs/gdb_25.html#SEC240">GDB/MI
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>
<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>
<br>
<img style="width: 730px; height: 237px;"
 alt="Debugger Console (default)" title="Debugger Console (default)"
 src="Pictures/Debugger_Console_2.JPG"><br>
<br>
This is probably another reason why "GDB Debugger Console" is hidden.<br>
<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"
shows:<br>
<ul>
  <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>
</ul>
<img style="width: 854px; height: 407px;"
 alt="Editor, Debugging Session is active"
 title="Editor, Debugging Session is active"
 src="Pictures/Editor_Debug.JPG"><br>
<br>
If there is no debugging session, only breakpoint annotations are shown
in the "Editor".<br>
<br>
<h2><a name="9._Menu_Toolbar_Buttons_and_Hot_Keys._"></a>9. Menu,
Toolbar Buttons and Hot Keys.</h2>
<br>
<img style="width: 364px; height: 64px;" alt="Debugging Toolbar Buttons"
 title="Debugging Toolbar Buttons"
 src="Pictures/Debug_Toolbar_Buttons.JPG"><br>
<br>
There are 11 toolbar buttons, related to debugging: <br>
<ul>
  <li>Debug Main Project (F5)</li>
  <li>Attach Debugger...<br>
  </li>
  <li>Finish Debugging Session (Shift+F5)<br>
  </li>
  <li>Pause</li>
  <li>Continue (Ctrl+F5)</li>
  <li>Step Over (F8)<br>
  </li>
  <li>Step Into (F7)<br>
  </li>
  <li>Step Out (Ctrl+F7)<br>
  </li>
  <li>Run to Cursor (F4)</li>
  <li>Apply Code Changes<br>
  </li>
  <li>New Watch... (Ctrl+Shift+F7)<br>
  </li>
</ul>
<br>
Three of them are not implemented in this release:<br>
<ul>
  <li>Attach Debugger... </li>
  <li>Run to Cursor </li>
  <li>Apply Code Changes</li>
</ul>
They are not removed from the toolbar, because they are used in Java
debugging. <br>
<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="http://cnd.netbeans.org/issues/show_bug.cgi?id=90120">IZ 90120</a>).<br>
<br>
<hr style="width: 100%; height: 2px;"><br>
<h4>Nikolay Molchanov</h4>
December 2006<br>
<br>
<br>
</body>
</html>

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
 
 
Close
loading
Please Confirm
Close