474-478.html
来自「linux-unix130.linux.and.unix.ebooks130 l」· HTML 代码 · 共 194 行
HTML
194 行
<HTML>
<HEAD>
<TITLE>Linux Unleashed, Third Edition:Programming in C</TITLE>
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!--ISBN=0672313723//-->
<!--TITLE=Linux Unleashed, Third Edition//-->
<!--AUTHOR=Tim Parker//-->
<!--PUBLISHER=Macmillan Computer Publishing//-->
<!--IMPRINT=Sams//-->
<!--CHAPTER=26//-->
<!--PAGES=474-478//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="472-474.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="478-482.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H4 ALIGN="LEFT"><A NAME="Heading13"></A><FONT COLOR="#000077">xxgdb</FONT></H4>
<P><TT>xxgdb</TT> is an X Window system-based graphical user interface to <TT>gdb</TT>. All of the features that exist in the command-line version of <TT>gdb</TT> are present in <TT>xxgdb</TT>. <TT>xxgdb</TT> enables you to perform many of the most commonly used <TT>gdb</TT> commands by pressing buttons instead of typing in commands. It also graphically represents where breakpoints have been placed.</P>
<P>Start <TT>xxgdb</TT> by typing the following into an <TT>Xterm</TT> window.</P>
<!-- CODE SNIP //-->
<PRE>
xxgdb
</PRE>
<!-- END CODE SNIP //-->
<P>When we initiate <TT>xxgdb</TT>, we can specify any of the command-line options that were available with <TT>gdb</TT>. <TT>xxgdb</TT> also has some of its own command-line options. These are described in Table 26.2.</P>
<TABLE WIDTH="100%"><CAPTION ALIGN=LEFT><B>Table 26.2.</B> The <TT>xxgdb</TT> command-line options.
<TR>
<TH COLSPAN="3"><HR>
<TR>
<TH WIDTH="15%" ALIGN="LEFT">Option
<TH WIDTH="85%" ALIGN="LEFT">Description
<TR>
<TH COLSPAN="3"><HR>
<TR>
<TD><TT>db_name</TT>
<TD>Specifies the name of the debugger to be used. The default is <TT>gdb</TT>.
<TR>
<TD><TT>db_prompt</TT>
<TD>Specifies the debugger prompt. The default is <TT>gdb</TT>.
<TR>
<TD VALIGN="TOP"><TT>gdbinit</TT>
<TD>Specifies the filename of the initial <TT>gdb</TT> command file. The default is <TT>.gdbinit</TT>.
<TR>
<TD><TT>nx</TT>
<TD>Tells <TT>xxgdb</TT> not to execute the <TT>.gdbinit</TT> file.
<TR>
<TD><TT>bigicon</TT>
<TD>Uses a large icon size for the <TT>xxgdb</TT> icon.
<TR>
<TD COLSPAN="3"><HR>
</TABLE>
<P>When you start <TT>xxgdb</TT>, a window opens on your screen. This window is shown in Figure 26.1.</P>
<P><A NAME="Fig1"></A><A HREF="javascript:displayWindow('images/26-01.jpg',554,324 )"><IMG SRC="images/26-01t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/26-01.jpg',554,324)"><FONT COLOR="#000077"><B>Figure 26.1.</B></FONT></A> The <TT>xxgdb</TT> main window.
</P>
<P>The <TT>xxgdb</TT> main window contains a message that is similar to the one displayed on the screen when the command line version of <TT>gdb</TT>is started. Near the bottom of the <TT>xxgdb</TT> main window there are four buttons. The Source Listing, Command Buttons, and Display Window buttons each bring up an additional window when they are activated. The Quit button terminates the <TT>xxgdb</TT> program.</P>
<P>The Source Listing button brings up a window that displays the source code for the program that is being debugged. This window is shown in Figure 26.2.</P>
<P><A NAME="Fig2"></A><A HREF="javascript:displayWindow('images/26-02.jpg',554,279 )"><IMG SRC="images/26-02t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/26-02.jpg',554,279)"><FONT COLOR="#000077"><B>Figure 26.2.</B></FONT></A> The <TT>xxgdb</TT> source listing window.
</P>
<P>The Command Buttons button brings up a window that contains 26 other buttons. These buttons each execute a <TT>gdb</TT> command. The <TT>gdb</TT> command-button window is illustrated in Figure 26.3.</P>
<P><A NAME="Fig3"></A><A HREF="javascript:displayWindow('images/26-03.jpg',194,389 )"><IMG SRC="images/26-03t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/26-03.jpg',194,389)"><FONT COLOR="#000077"><B>Figure 26.3.</B></FONT></A> The <TT>xxgdb</TT> command-button window.
</P>
<P>The Display Window button brings up a window that is used to display the results of any display command. You can tell <TT>xxgdb</TT> which variable or expression to display by selecting it from the source listing and then clicking on the Display button in the command-button window. The display window is illustrated in Figure 26.4.</P>
<P><A NAME="Fig4"></A><A HREF="javascript:displayWindow('images/26-04.jpg',312,129 )"><IMG SRC="images/26-04t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/26-04.jpg',312,129)"><FONT COLOR="#000077"><B>Figure 26.4.</B></FONT></A> The <TT>xxgdb</TT> display window.
</P>
<P>For more information on using <TT>xxgdb</TT>, refer to the <TT>xxgdb</TT> man page and the <TT>gdb</TT> man page.</P>
<H4 ALIGN="LEFT"><A NAME="Heading14"></A><FONT COLOR="#000077">calls</FONT></H4>
<P><TT>calls</TT> is a program that is not included on the Linux CD-ROM accompanying this book, but you can obtain a copy from the <TT>sunsite</TT> FTP site under the directory <TT>/pub/Linux/devel/lang/c/calls.tar.Z</TT>. Some older CD-ROM distributions of Linux include this file. Because it is a useful tool, we will cover it here. If you think it will be of use to you, obtain a copy from an FTP or BBS site or another CD-ROM. <TT>calls</TT> runs the GCC preprocessor on the files that are passed to it on the command line and displays a function call tree for the functions that are in those files.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>Tip: </B><BR>To install <TT>calls</TT> on your system, perform the following steps while you are logged in as <TT>root</TT>:
<DL>
<DD><B>1.</B> Uncompress and <TT>untar</TT> the file.
<DD><B>2.</B> <TT>cd</TT> into the <TT>calls</TT> subdirectory that was created by the <TT>untar</TT> command.
<DD><B>3.</B> Move the file named <TT>calls</TT> to the <TT>/usr/bin</TT> directory.
<DD><B>4.</B> Move the file named <TT>calls.1</TT> to the <TT>/usr/man/man1</TT> directory.
<DD><B>5.</B> Remove the <TT>/tmp/calls</TT> directory.
</DL>
<P>This will install the <TT>calls</TT> program and man page on your system.<HR></FONT>
</BLOCKQUOTE>
</P>
<P>When <TT>calls</TT> prints out the call trace, it includes the filename in which the function is found in brackets after the function name.</P>
<!-- CODE SNIP //-->
<PRE>
main [test.c]
</PRE>
<!-- END CODE SNIP //-->
<P>If the function is not in one of the files passed to <TT>calls</TT>, it does not know where that function lives and only prints the function name.</P>
<!-- CODE SNIP //-->
<PRE>
printf
</PRE>
<!-- END CODE SNIP //-->
<P><TT>calls</TT> also makes note of recursive and static functions in its output. Recursive functions are represented in the following way:</P>
<!-- CODE SNIP //-->
<PRE>
fact <<< recursive in factorial.c >>>
</PRE>
<!-- END CODE SNIP //-->
<P>Static functions are represented as follows:
</P>
<!-- CODE SNIP //-->
<PRE>
total [static in calculate.c]
</PRE>
<!-- END CODE SNIP //-->
<P>As an example, assume that calls were executed with the following program as input:
</P>
<!-- CODE //-->
<PRE>
##include <stdio.h>
main ()
{
char my_string[] = “hello there”;
my_print (my_string);
my_print2(my_string);
}
my_print (char *string)
{
printf (“The string is %s\n”, string);
}
my_print2 (char *string)
{
char *string2;
int size, size2, i;
size = strlen (string);
size2 = size -1;
string2 = (char *) malloc (size + 1);
for (i = 0; i < size; i++)
string2[size2 - i] = string[i];
string2[size] = ’\0’;
printf (“The string printed backward is %s\n”, string2);
}
</PRE>
<!-- END CODE //-->
<P>This generates the following output:
</P>
<!-- CODE SNIP //-->
<PRE>
1 main [test.c]
2 my_print [test.c]
3 printf
4 my_print2 [test.c]
5 strlen
6 malloc
7 printf
</PRE>
<!-- END CODE SNIP //-->
<P><TT>calls</TT> recognizes a number of command-line options that enable you to specify the appearance of the output and which function calls get displayed. For more information on these command-line options, refer to the <TT>calls</TT> man page or enter <TT>calls -h</TT> at the command line.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="472-474.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="478-482.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?