Update debugging example

Update the debugging example to use make to make sure the debuggable `runsc`
binary is installed as a docker runtime before attempting to start a container.
Also use nginx as an example container and Accept as an example break point
since it's easy to trigger.

PiperOrigin-RevId: 379393892
This commit is contained in:
Ian Lewis
2021-06-14 18:50:14 -07:00
committed by gVisor bot
parent 20c6816045
commit bccc446154
+25 -10
View File
@@ -61,24 +61,39 @@ You can debug gVisor like any other Golang program. If you're running with
Docker, you'll need to find the sandbox PID and attach the debugger as root.
Here is an example:
Install a runsc with debug symbols (you can also use the
[nightly release](../install/#nightly)):
```bash
# Get a runsc with debug symbols (download nightly or build with symbols).
bazel build -c dbg //runsc:runsc
make dev BAZEL_OPTIONS="-c dbg"
```
# Start the container you want to debug.
docker run --runtime=runsc --rm --name=test -d alpine sleep 1000
Start the container you want to debug using the runsc runtime with debug
options:
# Find the sandbox PID.
docker inspect test | grep Pid | head -n 1
```bash
docker run --runtime=$(git branch --show-current)-d --rm --name=test -p 8080:80 -d nginx
```
# Attach your favorite debugger.
sudo dlv attach <PID>
Find the PID and attach your favorite debugger:
# Set a breakpoint and resume.
break mm.MemoryManager.MMap
```bash
sudo dlv attach $(docker inspect test | grep Pid | head -n 1 | grep -oe "[0-9]*")
```
Set a breakpoint for accept:
```bash
break gvisor.dev/gvisor/pkg/sentry/socket/netstack.(*SocketOperations).Accept
continue
```
In a different window connect to nginx to trigger the breakpoint:
```bash
curl http://localhost:8080/
```
## Profiling
`runsc` integrates with Go profiling tools and gives you easy commands to