Cách khắc phục lỗi debug trong lúc options trên visual năm 2024

Chúng ta cần xác định các điểm mà tại đó việc thực hiện chương trình sẽ tạm dừng để điều tra. Chúng được gọi là breakpoints (điểm dừng, tức là chương trình sẽ dừng tại đó để điều tra đó) và được áp dụng cho các methods. Chúng cũng có thể được xác định bất cứ lúc nào trước hoặc trong khi execution. Cơ bản thì có 3 cách để thêm breakpoint vào chương trình:

  • Chuột phải vào marker bar, chọn Toggle Breakpoint
  • Ấn vào dòng bạn muốn debug, ấn ctrl + shift + b
  • Nhấp chuột 2 lần vào marker bar ở dòng bạn muốn debug
    Cách khắc phục lỗi debug trong lúc options trên visual năm 2024

2.1.3. Code-Flow Controls (Eclipse)

Giờ cùng thử thao tác để xem debug giúp tao làm những gì nào

Cách khắc phục lỗi debug trong lúc options trên visual năm 2024
Cách khắc phục lỗi debug trong lúc options trên visual năm 2024
Các debug options được sử dụng phổ biến nhất:

  • Step Into (F5) - Thao tác này đi vào bên trong các phương thức được sử dụng trong dòng hiện tại (nếu có); còn không thì nó nhảy tới dòng tiếp theo. Trong ví dụ này, nó sẽ debug vào bên trong phương thức gamePlay ().
    Cách khắc phục lỗi debug trong lúc options trên visual năm 2024
  • Step Over (F6) - Thao tác này xử lý dòng hiện tại và chuyển sang dòng tiếp theo. Trong ví dụ này, điều này sẽ thực thi phương thức gamePlay() và tiến hành dòng tiếp theo. Thường thì ta hay sử dụng cái này vì nếu là mình, mình sẽ đặt luôn breakpoint trong hàm luôn nên lúc debug nó sẽ chạy vào trong hàm luôn, lúc nào ấn F6 để nó chạy từng dòng một để mình điều tra từng dòng.
  • Step Return (F7) - Thao tác này kết thúc phương thức hiện tại và đưa chúng ta trở lại phương thức gọi. Trong trường hợp này, nếu có một breakpoint ở dòng 30 tức là đang set breakpoint ở bên trong method gamePlay() thì khi ấn F7 nó sẽ nhảy tới dòng 18, nơi method gamePlay() được gọi trong hàm Main().
  • Resume (F8) - Thao tác này sẽ chạy như bình thường mà không ngừng đến khi chương trình kết thúc trừ khi nếu mình đặt bất kì breakpoint ở các xử lí tiếp theo.

3. Techniques

Thường thì ta sẽ dùng debug để check xem giá trị biến hay giá trị ở dòng đó là gì, có như ta mong muốn hay không? Cũng có thể, t sử dụng debug để tìm hiểu xem luồng hay nghiệp vụ của chương trình chạy ra sao?

  • Khi debug chạy tới dòng nào thì các bạn có thể ấn vào luôn hàm hay biến đó tùy thuộc, rồi xem giá trị của nó
  • Ngoài ra có thể vào variables view tab để xem giá trị của các biến mỗi khi debug chạy tới như ví dụ sau:
    Cách khắc phục lỗi debug trong lúc options trên visual năm 2024

Cám ơn các bạn đã đọc, phần tiếp theo mình sẽ làm về Visual Studio, nếu có sai sót gì thì các bạn comment cho mình biết nhé.

Hãy nâng cấp lên Microsoft Edge để tận dụng các tính năng mới nhất, bản cập nhật bảo mật và hỗ trợ kỹ thuật.

Configure Edit and Continue (C#, VB, C++)

  • Bài viết
  • 12/14/2023

Trong bài viết này

You can disable or enable Hot Reload, previously called Edit and Continue, in the Visual Studio Options dialog box at design time. Hot Reload works only in debug builds. For more information, see Hot Reload.

Edit and Continue is a time-saving feature that enables you to make changes to your source code while your program is in break mode. When you resume execution of the program by choosing an execution command like Continue or Step, Edit and Continue automatically applies the code changes with some limitations. This allows you to make changes to your code during a debugging session, instead of having to stop, recompile your entire program, and restart the debugging session.

You can disable or enable Edit and Continue in the Visual Studio Options dialog box at design time. Edit and Continue works only in debug builds. For more information, see Edit and Continue.

For native C++, Edit and Continue requires using the /INCREMENTAL option. For more information about feature requirements in C++, see this blog post and Edit and Continue (C++).

Enable and configure Hot Reload

You can configure Hot Reload by selecting Settings from the Hot Reload drop-down button.

Cách khắc phục lỗi debug trong lúc options trên visual năm 2024

Or, open Tools > Options > Debugging > .NET/C++ Hot Reload.

Note

If IntelliTrace is enabled and you collect both IntelliTrace events and call information, Edit and Continue is disabled. For more information, see IntelliTrace.

The settings for Hot Reload include:

  • Enable Hot Reload and Edit and Continue when debugging. Enables Hot Reload when starting with the debugger attached (F5).
  • Enable Hot Reload when starting without debugging. Enables Hot Reload when starting without the debugger attached (Ctrl+F5).
  • Apply Hot Reload on File Save. Applies code changes when you save the file.
  • Logging Verbosity. Filters amount of information displayed in the Hot Reload Output window.

Cách khắc phục lỗi debug trong lúc options trên visual năm 2024

For .NET Hot Reload, you also can control whether Hot Reload is available at the project level by modifying your .NET 6+ project's launchSetting.json file and setting hotReloadEnabled to false.

Example:

{
  "profiles": {
    "Console": {
      "commandName": "Project",
      "hotReloadEnabled": false
    }
  }
}

For C++, you can set additional options by opening Tools > Options > Debugging > General. Make sure Enable Hot Reload is selected, and set the other options:

  • Apply changes on continue (Native only) If selected, Visual Studio automatically compiles and applies code changes when you continue debugging from a break state. Otherwise, you can choose to apply changes using Debug > Apply Code Changes.
  • Warn about stale code (Native only) If selected, gives warnings about stale code.

Enable or disable Edit and Continue

  1. If you're in a debugging session, stop debugging (Debug > Stop Debugging or Shift+F5).
  2. In Tools > Options > (or Debug > Options) > Debugging > General, select Edit and Continue in the right pane. Note If IntelliTrace is enabled and you collect both IntelliTrace events and call information, Edit and Continue is disabled. For more information, see IntelliTrace.
  3. For C++ code, make sure Enable Native Edit and Continue is selected, and set the other options:
    • Apply changes on continue (Native only) If selected, Visual Studio automatically compiles and applies code changes when you continue debugging from a break state. Otherwise, you can choose to apply changes using Debug > Apply Code Changes.
    • Warn about stale code (Native only) If selected, gives warnings about stale code.
  4. Select OK.

Stop code changes

While Hot Reload is in the process of applying code changes, you can stop the operation.

While Edit and Continue is in the process of applying code changes, you can stop the operation.

Caution

Stopping code changes in managed code can produce unexpected results. Applying changes to managed code is normally a quick process, so there is seldom a need to stop code changes in managed code.