[Tip] vs2019 debugging

1. The origin of computer bugs

  The most famous origin story of the computer term "bug" goes like this: In 1943, Hopper was working for the U.S. Navy, at the height of World War II. The Mark-1 computer was huge, and if there was a glitch, it was difficult to find. But Hopper eventually discovered the problem, because there was a moth stuck in the internal structure. She made a specimen of the moth in her notebook and wrote an article dated September 9 next to it. According to the Navy website, this was the first real case of a bug being found and the origin of the word bug.

Insert image description here
Character: Hopper,
Insert image description here
  must what you see be the truth?
 Hopper's paper shows that she and others had been using the term to refer to computer problems for several years before the moth incident. In fact, the bug even predates Hopper himself. According to the Oxford English Dictionary, it first appeared in a newspaper describing Edison. In 1889, a writer for the Pall Mall Gazette wrote: "Mr. Edison spent two nights fixing 'a bug', a phrase used to express problem-solving. It's like there's a bug hiding in the gramophone that's causing all this trouble." However, the word bug had appeared in Edison's personal diaries and letters as early as 1876, long before this report.
 So how did Edison come up with this word? "Computer World" points out that the word can be traced back to an ancient word for monster. It is still present in some uncommon words, such as bugaboo (something that is annoying or frightening). But Edison coined the word from a literal bug. He imagined some bugs trapped in the machine's holes. In an 1878 letter, he wrote: “Technical bugs require months of observation, study, and labor to reveal themselves before commercial success or failure. After all, you are looking at apartments. You never notice cockroaches when you are living there, they are exposed only after you live in them."
 So why is the Hopper moth incident the first thing that comes to mind when we talk about bugs? This is still thanks to Hopper himself. Because in the years after 1944, she told the story of the moth in the computer again and again, adding at one point: "From then on, when there was a problem with the computer, we said it had a bug. Then Eliminating bugs is called debugging .

2. Debugging

1. Definition of debugging

 After programming, use various means to check and troubleshoot errors . The correctness of a program is not only reflected in the completion of normal functions, but more importantly, the correct handling of unexpected situations. From a psychological perspective, developers and debuggers should not be the same person .

2.Basic steps for debugging

1. Discover the existence of program errors
2. Locate the errors by isolating and eliminating them
3. Determine the cause of the errors
4. Propose solutions to correct the errors
5. Correct the program errors and retest

Every debugging is a process of solving a case, searching for a few clues, and finally finding the bug.

2.The difference between release and debug

  Debug version: Usually called the debug version, it contains debugging information and does not make any optimization to facilitate programmers to debug the program .
  Release version: It is called a release version. It often carries out various optimizations to make the program optimal in terms of code size and running speed, so that users can use it well and cannot debug .

3. Shortcut keys for debugging

1. F5: Start debugging
2. Ctrl+F5: Start execution (without debugging)
3. Shift+F5: Stop debugging
4. Ctrl+Shift+F5: Restart debugging
5. F9: Enable/disable breakpoints
6. Ctrl+F9 : Stop breakpoint
7. Ctrl+Shift+F9: Delete all breakpoints
8. F10: Step by step
9. Ctrl+F10: Run to cursor
10. F11: Step by statement

4. Shortcut keys for other functions

1. Window shortcut keys

Memory tip: Any shortcut key linked to a window must have a W (Windows); Ctrl+W, W: browser window (youdao's translation for window shopping is window shopping
)

Ctrl+W,S: Solution Manager (Solution)

Ctrl+W,C: Class view (Class)

Ctrl+W,E: Error list (Error)

Ctrl+W,O: Output window (output Output; output the compilation information of the program
; you can configure what information you need to view in "Tools" - "Options" - "Debugging" - "Output Window" in vs)

Ctrl+W,P: Property window (Property)

Ctrl+W,T: Task list (Task)

Ctrl+W
, The key is "X")

Ctrl+W,B: Bookmark window (Bookmark Bookmark is very easy to use. If there are thousands of lines of code, adding a bookmark when looking for code will make it much faster)

Ctrl+W,U: Document outline (OutLine; use the second letter U)

Ctrl+D,B: Breakpoint window (breakpoint)

Ctrl+D,I: Immediate window (immediately)

2. Project function shortcut keys**

Rule: ctrl is a mandatory function key, and shift adds functions to the project.

CTRL + F6 /CTRL + TAB The next document window is the active form switch (alt+tab in the Windows operating system means switching between tasks

CTRL + SHIFT + F6 /CTRL + SHIFT + TAB previous document window (in Windows system operation,
I believe everyone knows that shift has the opposite function, haha, it is reflected here)

F7: View code (in WebForm development, it is to view the background code)

Shift+F7: View the form designer (this method is very convenient to jump to the foreground .aspx page when the cs file is in the background)

Ctrl+Shift+N: Create a new project (N means New, so if you need to force a new project in the project, the key combination is Ctrl+Shift+N)

Ctrl+Shift+O: Open project (Open)

CTRL + SHIFT + C displays the class view window (C stands for Class)

CTRL + F4 closes the document window (I believe everyone who has used QQ has used alt+f4 to close the current chat window.
If you think about using ctrl+tab to switch between active tab windows, you will know why closing the current tab window is ctrl+f4)

CTRL + SHIFT + E displays the resource view (E stands for Explorer)

CTRL + SHIFT + B to generate the solution (B stands for Build, which can also be achieved with F6)

Shift+F6 means to generate the current project (as mentioned above, you can use f6 to generate the entire solution. If it is the generation of the current project, then naturally add the function key shift)

F4 displays the properties window SHIFT + F4 displays the project properties window

Ctrl+Shift+S: Save all (S stands for Save. Here it means save all because if it is just a single save, Ctrl+S has nothing to do with the entire project. The concept of
saving all should mean in the entire project, so in the key combination Naturally there will be a shift)

Ctrl+Shift+A: Create a new item (A means Add)

Shift+Alt+C: Create a new class
(shift is a function key related to the project; Alt is used a lot, next to spaces (used a lot); C is Class; and adding classes is used a lot; so naturally: Shift +Alt+C)

3. Find related shortcut keys

Ctrl+F: Find (Find) Ctrl+Shift+F: Search in the file (as mentioned above, shift means in the project, so if you need to search in the files in the project, then Shift is naturally indispensable) F3:
Search Next
(I believe anyone who has used the Windows system knows that f3 is the shortcut key for search) Shift+F3: Find the previous one (shift has a reverse function here) Ctrl+H:
Replace Ctrl+Shift+H: In the file replace in

4. Code shortcut keys

Ctrl+E,D (ctrl+k,d) - Format all code; make your code tidy instantly.

Ctrl+E,F —-Format selected code

Ctrl+K,C: Annotate selected content

Ctrl+K,U: Deselect the annotation content

Ctrl+J /Ctrl+K,L: Smart prompt to list members (kernel core content list list.
If we want to view the specific information of the members of an object, try this shortcut key)

Ctrl+K,P: Parameter information (kernel core content Parameters parameter
This key combination is quite useful if we want to view the specific parameters of a method)

Ctrl+K,I: Quickly view information (Information)

Ctrl+K,S: External code (I usually use #region from time to time. After using region, the code looks particularly neat.

CTRL + M, CTRL + M collapse or expand the current method

CTRL + M, CTRL + O collapse all methods

CTRL + M, CTRL + L to expand all methods CTRL + M, CTRL + P to expand all methods

Ctrl+M,P: Stop the outline display (after using region to fold the code, try using this set of key combinations to experience the folding and unfolding effect) Ctrl+
shift+f10: Automatically add the using namespace (in the instantiated object , used a lot)

5. Edit shortcut keys

Shift+Alt+Enter: Switch to full screen editing

F12: Go to the definition of the called procedure or variable

Alt+F12: Search for symbols (list all search results)

shift+f12: Find all references (place the cursor on the word, then press Shift + F12)

Ctrl+U: Convert all sql statements to lowercase (convert all sql statements to uppercase to improve performance)

Ctrl+Shift+U: Change all to uppercase (U means Upper)

Ctrl+Shift+V: Clipboard loop

Ctrl+Shift+L: Delete the current line

Ctrl+E,S: View blank space (ctrl+r,w can also view blank space or show or hide tab marks)

Ctrl+E,W: Automatic line wrap

Ctrl+G: Go to the specified line (it is very convenient to use it when we want to jump to a specific line)

Shift+Alt+arrow keys: select rectangular text Alt+left mouse button: select rectangular text

CTRL + DELETE to delete to the end of the word CTRL + BACKSPACE to delete to the beginning of the word SHIFT + TAB to cancel the tab character

Ctrl + left and right arrow keys: move one word at a time

Ctrl+click: Select the entire word currently clicked

SHIFT + END to select to the end of the line SHIFT + HOME to select to the beginning of the line

CTRL + SHIFT + END to select to the end of the document CTRL + SHIFT + HOME to select to the end of the document

CTRL + SHIFT + PAGE UP to select to the front of this page CTRL + SHIFT + PAGE DOWN to select to the back of this page

CTRL + PAGE DOWN The cursor is positioned above the window CTRL + PAGE UP The cursor is positioned below the window

CTRL + END documents are positioned at the end. CTRL + HOME documents are positioned at the front.

Press tab twice to quickly activate the code segment (write for, foreach loop, or try, and bind event methods)

ctrl+minus sign: Go back to the last position of the cursor

5. Classic examples

#include <stdio.h>

int main()
{
    
    	
	int i = 0;
	
	int arr[10] = {
    
     1,2,3,4,5,6,7,8,9 };
	
	for (i = 0; i <= 12; i++)
	{
    
    
		arr[i] = 0;
		printf("%d", arr[i]);//死循环
	}
	
	return 0;
}

Illustration:
Insert image description here

6. Good habits for writing code

  1. Use assert - header file: assert.h
  2. Try to use const
  3. Develop good coding style
  4. Add necessary comments
  5. Avoid coding pitfalls.

Example: Simulate implementation of strcpy

char * strcpy(char * dst, const char * src)
{
    
    
	char * cp = dst;
	assert(dst && src);
	while( *cp++ = *src++ )
	{
    
    
	   ;
	}
	return( dst );
}

Illustration:
Insert image description here

7.The role of const

Motto: Whoever is close to you cannot move.

int main()
{
    
    
	int a = 10;
	int b = 0;
	int* p = &a;
	return 0;
}

Insert image description here

8. Common mistakes in programming

7.1 For compilation errors,
see the error message directly (double-click) to solve the problem. Or you can do it with experience . Relatively simple.
7.2 For link-type errors,
look at the error message , mainly find the identifier in the error message in the code, and then locate the problem. Usually the identifier name does not exist or is spelled incorrectly.
7.3 Runtime errors
use debugging to gradually locate the problem . The most difficult thing to do.

Summarize

 Debugging skills require us to accumulate experience step by step in actual situations. Eventually we will all become big guys. If you think the article is good, you might as well give it a three-in-a-row reward! Thank you!

Guess you like

Origin blog.csdn.net/Shun_Hua/article/details/128457512