Godebug: A cross-platform Go Program debugging tool

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed. Godebug is a cross-platform Go Program debugging tool, the traditional compiler language debugger uses the underlying system to invoke and read binary files for debugging various symbols. It's cumbersome and difficult to transplant.

Godebug uses different methods, direct the source code as the target program, insert the debug code in each line, and then compile and run. The result is a fully functional debugger that can be ported to different platforms. In fact, because of the GOPHERJS, you can also debug on the browser:



Click here to try the original debug window. With the "Debug It" button in the original, you can edit the program and re-debug it.

Working principle

The following is a vector diagram describing the above example:



You can see that the original code was converted two times: the first time Godebug inserts the debug instrumentation, and then GOPHERJS compiles the results into JavaScript.

Let's take a look at the instrumentation step, the following is the invocation of the Godebug insert:
    • Godebug. Enterfunc: Let the Godebug run-time library know that we are entering a function. Because "next" does not stop the internal function calls, the runtime library takes note of these calls and knows when to skip the rows.
    • Godebug. Exitfunc: Let the Godebug run-time library know that we are leaving a function, omitted in main.
    • Godebug Runtime Library: When a user pauses a program and waits for input only when it is told by a command or a breakpoint, it prompts the user to enter and respond to any command.
    • Godebug. Declare: Records the mapping of variable names and values. The map is used by the output command.

using Godebug

Step 1. Installation



Step 2: Set breakpoints

Add this tag wherever you want the breakpoint to be:



Because breakpoints are part of the source code, you can put your own logic around them. Assuming you are running a table-driven multi-condition test where one of the test inputs "weird string" is unsuccessful, you can put the following breakpoint into the test:



Godebug test will pause the program at the marker for easy positioning.

Step 3: Run the program

To run a command using Godebug:



Or, for testing, run the test command:



By default, Godebug only adds debug instrumentation to the package main (for Godebug) or the package under test (for godebug testing). This means that, by default, you cannot enter a function from an imported package. When needed, execute the following line command:



finally

Godebug is still a new tool that needs polishing, and the known limitations currently exist include:
    • Performance Overhead
    • May cause a read conflict if your program reads from stdin
    • Unable to attach a running process
    • Before you start, you need to know the package you're asking for debugging.

It enters at the address point on GitHub.

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.