Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/eze-kiel/dbg

Golang embeddable debugger
https://github.com/eze-kiel/dbg

Last synced: 4 days ago
JSON representation

Golang embeddable debugger

Awesome Lists containing this project

README

        

# dbg

Lightweight and easy-to-use embeddable debugger for Go.

`dbg` provides basic informations such as the position in the program, the caller function, the memory usage etc. with a colored output.

![Sample](img/example.png)

## Getting started

```
$ go get github.com/eze-kiel/dbg
```

## Usage

### Display infos at a given position

Adding `dbg.Point()` somewhere in your program will display some informations about the place:

Example

```go
func main() {
dbg.Point()
}
```

Output:

```
(pkg:main|func:main) main.go:6
```

You can also give arguments to `Point()`, for example to display the content of an object. Its type will be shown next to its value.

Example

```go
func main() {
myvar := 1337
dbg.Point(myvar)
}
```

Output:

```
(pkg:main|func:main) main.go:7 1337 (int)
```

Another function, `dbg.Printf()` emulates the behavior of `fmt.Printf` but adds the debugger prefix:

Example

```go
func main() {
name := "General Kenobi"
dbg.Printf("hello there, %s\n", name)
}
```

Output:

```
(pkg:main|func:main) main.go:7 hello there, General Kenobi
```

### Display memory stats

`dbg.Mem()` allows you to see some memory informations. Its does not require any parameter.

### Stop program execution

`dbg.Halt(code int)` allows you to stop the program execution with a given error code.