Linux development tools-gdb (I) and linux development tools-gdb

Source: Internet
Author: User

Linux development tools-gdb (I) and linux development tools-gdb
Iii. gdb debugging (I) 01.gdb: gdb is short for GNU debugger and is a programming debugging task. Function: start the program and run the program as needed according to user-defined requirements; the program to be debugged can be stopped at the breakpoint specified by the user (the breakpoint can be a conditional expression); when the program stops, it can detect what happens in the program at this time; dynamically change the execution environment of the program. # Vi smiple. c # include <stdio. h> # include <stdlib. h> long func (int n); int main (int argc, char * argv []) {printf ("Entering main... \ n "); int I; long result = 0; for (I = 1; I <= 100; I ++) {result + = I ;} printf ("result [1-100] = % ld \ n", result); printf ("result [1-10]", func (10); return 0 ;} long func (int n) {long sum = 0; int I; for (I = 1; I <n; I ++) {sum + = 1 ;}return sum ;}: wq # gcc-Wall-g (to generate debugging and display the source file) simple. c-o simple #. /simple # gdb Simple (gdb) list (display all source code) (gdb) l (same as above) (gdb) break 10 (set breakpoints in line 10th) (gdb) info break (view breakpoint Information) -- ib (abbreviation) (gdb) B func (Set breakpoint at function entry) (gdb) run -- r (run to breakpoint) (gdb) step -- s (single-step tracking) (gdb) print I -- p I (print the current value of I) (gdb) p resultresult = 3 (gdb) p I (gdb) s (gdb) until (jump out of the for loop, the next statement of the loop) (gdb) c (continue to run to the next breakpoint) (gdb) Press enter directly, use the previous command (gdb) finish (end one-step debugging) # vi Makefile. PHONY: clean allCC = gccCFLAGS =-Wall-gBIN = simple mainall: $ (BIN) $ (CC) $ (CFLAGS)-c $ <-O $ @ main: main. o search. o $ (CC) $ (CFLAGS) & ^-o $ @ clean: rm-f *. o $ (BIN): wq # gdb simple (gdb) r a B c (add startup parameters to the program) (gdb) list fun (view the function source code of fun) (gdb) list file: fun (view the fun function source code in the file) 02. set breakpoint and Observation Point break row number break funbreak file: row number break file: funbreak if <condition>-when the condition is set, the program stops info break (I B) -Check that the checkpoint watch expr-variable expr value has changed, and the program stops deleting n-delete the checkpoint 03. one-step debugging of continue (c)-running to the next breakpoint step (s)-One-step tracing, entering the function, similar to step innext (n)-One-step tracking in VC, do not enter the function, Class Similar to step outfinish in VC-run the program until the current function is completed. The stack address, return value, and parameters returned by the function are printed. Until-when tired of one-step tracking in a loop body, this command can run the program until it exits print (p) to view the runtime variables and expressions

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.