In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article is to share with you about how to comprehensively analyze the Fedora GCC program, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
Before I give you a detailed introduction to Fedora GCC, let me first let you know about Linux, and then give a comprehensive introduction to Fedora GCC.
1. Command: [root@localhost ~] # gcc-g http2.c-o http2
Get debugging information:
[root@localhost] # gcc-g http2.c-o http2
Http2.c: in the function 'main':
Http2.c:51: warning: implicit declaration is not compatible with the built-in function 'bzero'
Http2.c:61: warning: convert between incompatible pointer types when passing parameter 2 (belonging to 'bind')
Http2.c:81: warning: convert between incompatible pointer types when passing parameter 2 (belonging to 'accept')
Http2.c: in the function 'ParseHttpRequest':
Http2.c:153: warning: implicit declaration is not compatible with the built-in function 'strstr'
Http2.c:153: warning: implicit declaration is not compatible with the built-in function 'strlen'
Http2.c:158: warning: implicit declaration is not compatible with the built-in function 'memset'
Http2.c:159: warning: implicit declaration is not compatible with the built-in function 'memcpy'
Http2.c: in the function 'do_proxy':
Http2.c:315: warning: implicit declaration is not compatible with the built-in function 'strcat'
Http2.c:316: warning: implicit declaration is not compatible with the built-in function 'strlen'
[root@localhost] #. / http2 is listening to [root@localhost ~] #
two。 To find the error more quickly, you can use GDB for trace debugging as follows:
[root@localhost ~] # gdb http2
GNU gdb Red Hat Linux (6.5-15.fc6rh)
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
Welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"... Using host libthread_db library "/ lib/libthread_db.so.1".
When the GDB prompt appears, indicating that GDB is ready for debugging, you can now use the run command to get the program running under the supervision of GDB: Starting program: / root/http2 is listening to Program exited normally.
3. The following is the information found. When the GDB prompt appears, it shows that GDB is ready for debugging. Now you can use the run command to get the program to run under the supervision of GDB:
Starting program: / home/xiaowp/thesis/gcc/code/crash
Input an integer:10
Program received signal SIGSEGV, Segmentation fault.
0x4008576b in _ IO_vfscanf_internal () from / lib/libc.so.6
After a careful analysis of the output given by GDB, it is not difficult to see that the program was aborted due to a segment error, indicating that there was a problem with the memory operation, and the specific problem occurred when calling the
_ IO_vfscanf_internal (). To get more valuable information, you can use the backtracking command backtrace provided by GDB to execute the results
As follows:
# 0 0x4008576b in _ IO_vfscanf_internal () from / lib/libc.so.6
# 1 0xbffff0c0 in? ()
# 2 0x4008e0ba in scanf () from / lib/libc.so.6
# 3 0x08048393 in main () at crash.c:11
# 4 0x40042917 in _ _ libc_start_main () from / lib/libc.so.6
Skip the first three lines of the output, and it's not hard to see from the fourth line of the output that GDB has located the error to line 11 in crash.c. Now check it carefully:
Frame 3 # 3 0x08048393 in main () at crash.c:11 11 scanf ("d", input)
Using the frame command provided by GDB, you can locate the code segment where the error occurred, and the value followed by this command can be found at the beginning of the line in the output of the backtrace command. Now the mistake has been found.
If there is a mistake, you should change scanf ("% d", input) to scanf ("% d", & input); when you are finished, you can exit GDB, as follows:
GDB is much more than that, it can also step through programs, check memory variables, set breakpoints, and so on. You may need to use the intermediate results generated by the compiler when debugging, so you can use the-save-temps option to have Fedora GCC save the preprocessing code, assembly code, and object code as files. If you want to check whether the generated code can be manually adjusted to improve execution performance, intermediate files generated during compilation can be helpful, as follows:
# Fedora GCC-save-temps foo.c-o foo
# ls foo*
Foo foo.c foo.i foo.s
Other debugging options supported by Fedora GCC include-p and-pg, which add Profiling information to the resulting binaries. Analyzing information is very helpful to find out the performance bottleneck of the program, and it is a powerful tool to assist Linux Fedora GCC programmers to develop high-performance programs. Adding the-p option at compile time adds statistics that can be recognized by the General profiling tool (Prof) to the generated code, while the-pg option generates statistics that are recognized only by the GNU profiling tool (Gprof).
As a reminder, although Fedora GCC allows debugging symbol information to be added at the same time as optimization, the optimized code can be a big challenge for debugging itself. After the code is optimized, the variables declared and used in the source program are likely to be no longer used, the control flow may suddenly jump to unexpected places, and loop statements may become ubiquitous as the loop unfolds, all of which will be a nightmare for debugging. It is recommended that you do not use any optimization options when debugging, and optimize the program only when it is finally released.
The above is how to comprehensively analyze the Fedora GCC program. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.