The debugger
When every other checking tool fails to detect the problem, then it is debugger's turn. A debugger allows working through the code line-by-line to find out what it is going wrong, where and why. It allows working interactively, controlling the execution of the program, stopping it at various times, inspecting variables, changing code flow whilst running.
In order to make use of a debugger, a program must be compiled with debugging information inserted. This information is provided by debugging symbols included by the compiler in the binaries. Debugging symbols describe where functions and variables are stored in memory. An executable with debugging symbols can run as a normal program, it is just slightly slower.
An important feature of debuggers is the possibility to set breakpoints. Breakpoints stop program execution on demand: the program runs normally until it is about to execute the piece of code at the same address of the breakpoint. At that point it drops back into the debugger to look at variables, or continue stepping through the code. Breakpoints are fundamental in interactive debugging, and accordingly have many options associated with them. They can be set up on a specific line number, at the beginning of a function, at a specific address, or conditionally (i.e. as soon as a condition is verified).
After stopping the program as a consequence of a breakpoint, a debugger can resume its execution. There are several ways in which this can be done. The debugger can execute just the next program line stepping over any function calls in the line. This way any call will be executed in one go, as if it were a single instruction. Alternatively, the debugger can step into a function call, executing also its code line by line. Obviously, the debugger can also go on running your program without performing any actions.
Another important feature that all decent debuggers must offer is the possibility to set watchpoints. Watchpoints are particular type of breakpoints which stop the code whenever a variable changes, even if the line doesn't reference the variable explicitly by name. Instead, a watchpoint looks at the memory address of the variable and alerts the programmer when something is written to it.
In large programs, adding breakpoints for every iteration of a loop is prohibitive. It is not necessary to step through each one in turn: a technique known as binary split can greatly simplify the debugging process. The technique consists in placing a breakpoint at the last line of the first half of the code, and running the code. If the problem does not manifest itself, then the fault is likely to be within the second half. From here, the procedure is repeated with the region where the problem is supposed to be, reducing the area under test at each iteration. At the end, the method either leaves you with just one line, or a sufficiently small routine that can be stepped through. A binary split [13] can limit the search area of a 1000 line program to just 10 steps!
Algorithm implementation errors are reasonably easy to track down with a debugger. Stepping through, looking for an invalid state or bad data, is enough: the last statement to execute either is itself wrong or at least points you at the problem.
ดีบัก
เมื่อทุกเครื่องมือการตรวจสอบล้มเหลวในการตรวจหาปัญหาแล้วมันเป็นจุดบกพร่องของการเปิด ดีบักช่วยให้ทำงานผ่านรหัสบรรทัด เพื่อหาสิ่งที่มันเกิดขึ้นที่ไหนและทำไม มันช่วยให้ทำงานโต้ตอบ ควบคุมการทำงานของโปรแกรม , การหยุดที่เวลาต่าง ๆ การตรวจสอบตัวแปรที่เปลี่ยนแปลงในขณะที่การไหลของรหัส
วิ่งเพื่อให้การใช้ดีบักโปรแกรมจะรวบรวมกับการแก้จุดบกพร่องข้อมูลแทรก ข้อมูลนี้มีให้โดยการดีบักสัญลักษณ์รวมโดยคอมไพเลอร์ในไบนารี การดีบักสัญลักษณ์อธิบายที่ฟังก์ชันและตัวแปรจะถูกเก็บไว้ในหน่วยความจำ ปฏิบัติการด้วยการดีบักสัญลักษณ์สามารถเรียกใช้เป็นโปรแกรมปกติ มันเป็นเพียงเล็กน้อยช้าลง
คุณสมบัติที่สำคัญของ debuggers มีความเป็นไปได้ที่จะตั้งจุด . จุดหยุดการประมวลผลโปรแกรมตามความต้องการ : โปรแกรมรันได้ตามปกติจนกว่าจะใช้ชิ้นส่วนของรหัสในที่อยู่เดียวกันของคนบ้านเดียวกัน . ที่จุดที่มันจะตกกลับเข้ามาในการดีบักเกอร์มองตัวแปร หรือต่อก้าวผ่านรหัส จุดเป็นพื้นฐานในการโต้ตอบการดีบักจึงมีตัวเลือกมากมายที่เกี่ยวข้องกับพวกเขา พวกเขาสามารถตั้งหมายเลขบรรทัดที่เฉพาะเจาะจงที่จุดเริ่มต้นของฟังก์ชันที่ที่อยู่ที่เฉพาะเจาะจงหรือเงื่อนไข ( เช่นทันทีที่เงื่อนไขความถูกต้อง ) .
หลังจากหยุดโปรแกรมเพราะเป็นคนบ้านเดียวกัน , ดีบักสามารถต่อการปฏิบัติของตน มีหลายวิธีที่สามารถทำดีบักสามารถใช้เพียงโปรแกรมบรรทัดถัดไปก้าวข้ามใด ๆเรียกฟังก์ชันในบรรทัด วิธีนี้แจ้งจะถูกประหารในหนึ่งไป ราวกับว่ามันเป็นคำสั่งเดียว หรือดีบักสามารถเข้าไปเรียกใช้ฟังก์ชัน , รันยังบรรทัดของรหัสโดยเส้น อย่างชัดเจน , ดีบักสามารถไปเรียกใช้โปรแกรมของคุณโดยไม่มีการกระทำใด ๆ .
คุณลักษณะสำคัญอื่นที่เหมาะสมทั้งหมดต้องเสนอ debuggers คือความเป็นไปได้ที่จะตั้งค่า watchpoints . watchpoints เป็นประเภทเฉพาะของจุดที่หยุดรหัส เมื่อตัวแปรเปลี่ยน ถ้าเส้นไม่อ้างอิงตัวแปรอย่างชัดเจนโดยใช้ชื่อ แทน watchpoint ดูหน่วยความจำที่อยู่ของตัวแปรและการแจ้งเตือนโปรแกรมเมอร์ เมื่อสิ่งที่ถูกเขียนไปยังมัน .
ในโปรแกรมขนาดใหญ่ , เพิ่มจุดพักทุกรูปของวงจะห้ามปราม ไม่จําเป็นต้องผ่านขั้นตอนแต่ละตัวในการเปิด : เป็นเทคนิคที่เรียกว่าไบนารีแยกสามารถง่ายขั้นตอนการแก้จุดบกพร่อง . เทคนิคประกอบด้วยในการวางจุดหยุดที่บรรทัดสุดท้ายของครึ่งแรกของรหัสและใช้รหัส ถ้าปัญหาไม่แสดงรายการตัวเองแล้วความผิดก็น่าจะภายในครึ่งหลัง จากที่นี่ , ขั้นตอนซ้ำกับพื้นที่ที่เป็นปัญหาต้องลดพื้นที่ภายใต้การทดสอบในแต่ละซ้ำ . สุดท้าย วิธีการให้ใบคุณมีเพียงหนึ่งบรรทัด หรือพอเล็กนที่สามารถก้าวผ่านไบนารีแยก [ 13 ] สามารถ จำกัด การค้นหาพื้นที่ 1000 บรรทัดโปรแกรมเพียง 10 ขั้นตอน ! การใช้ขั้นตอนวิธีที่เหมาะสม
ข้อผิดพลาดง่ายในการติดตามลงโปรแกรมดีบัก ก้าวผ่าน , ที่กำลังมองหาสถานะไม่ถูกต้อง หรือ ข้อมูล ที่ไม่ดีคือ พอ : ข้อความสุดท้ายที่จะดำเนินการอย่างใดอย่างหนึ่งคือตัวเอง ผิดหรือที่คะแนนน้อยเจ้าปัญหา
การแปล กรุณารอสักครู่..
