Solve the problem that C language project cannot be debugged under Linux __linux

Source: Internet
Author: User

Prepare to follow the Iostat (included in the Sysstat software package) source code. Create a new Makefile project in Eclipse and import the source code for Sysstat 9.1.3. Code can be compiled, compiled Iostat can also run normally. However, the breakpoint in the code does not work when Eclipse debugging runs but prompts "function ' main ' not defined."

Debugging with GDB at the command line also prompts "function ' main ' not defined" when a breakpoint is set on the main function.

The Iostat is disassembled with Objdump, and a "call __libc_start_main" is seen in the assembly code. In GdB, we set a breakpoint on the __libc_start_main function, succeeding, stepping through, but following the libc-start.c "result = Main (argc, argv, __environ main_auxvec_param)" This line will never be followed.

Build a contrast C project in Eclipse, compile it, and then use the Objdump disassembly to discover that the "symbol table". Symtab ' "In the disassembly result contains the symbol" main ", but not in the iostat of the front disassembly.

Then consider whether the GCC compilation parameters for the two projects are different, and then compare:

Iostat:
Compile:
Gcc-o iostat.o-c-g3-o0-wall-wstrict-prototypes-pipe-o0-dsa_dir=/"/var/log/sa/"-DSADC_PATH=/"/usr/local/lib/sa/s" adc/"-duse_nls-dpackage=/" sysstat/"-dlocaledir=/"/usr/local/share/locale/"iostat.c"
Link:
Gcc-o iostat-g3-o0-wall-wstrict-prototypes-pipe-o0 IOSTAT.O LIBRDSTATS.A libsyscom.a-s

Compare C Project:
Compile:
Gcc-o0-g3-wall-c-fmessage-length=0-mmd-mp-mf "TTT.D"-MT "TTT.D"-O "TTT.O" ". /ttt.c "
Link:
Gcc-o "Testtest"./TTT.O

A lot of differences in parameters, after a number of access to data, found that the problem in the Iostat link parameters of "-S", the GCC manual written "-S" role is "Remove all symbol table and relocation information from the" Executable ".

So into the Sysstat project makefile, "Lflags" in the "-S" deleted. In this way, the iostat can be debugged properly. I do not know much about GCC, this small problem on a half-day, but also let me learn a lot.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.