dbg:   debug applications remotely
1 Usage
1.1 Port Forwarding
2 Reference
2.1 Server
serve
2.2 Client
current-client
client?
connect
connected?
disconnect!
reconnect!
get-info
get-memory-use
get-object-counts
start-profile
stop-profile
get-profile
8.17

dbg: debug applications remotely๐Ÿ”—โ„น

Bogdan Popa <bogdan@defn.io>

This package provides a server, client and UI for remotely debugging Racket applications.

1 Usage๐Ÿ”—โ„น

Call serve before starting your app and use the returned function to stop the server when your app shuts down.

(require (prefix-in dbg: debugging/server))
(define dbg:stop (dbg:serve))

Then use the UI to interact with the server (raco dbg from the dbg-ui package). If youโ€™re feeling particularly adventurous, you can use the programmatic API (Client) instead.

1.1 Port Forwarding๐Ÿ”—โ„น

The server listens on the loopback interface by default, so itโ€™s not exposed to the internet. While you can tell it to listen on a different interface, that would likely be insecure. Instead, when you need to debug a remote server, you should use port forwarding. Hereโ€™s how you would forward port 9011 using the ssh command:

ssh -L 9011:127.0.0.1:9011 example.com

2 Reference๐Ÿ”—โ„น

The dbg package provides two top-level modules, representing the Server and Client APIs.

2.1 Server๐Ÿ”—โ„น

 (require debugging/server) package: dbg

procedure

(serve [#:host host #:port port]) โ†’ (-> void?)

  host : string? = "127.0.0.1"
  port : (integer-in 0 65535) = 9011
Runs a debugging server bound to port on host in the background and returns a function that stops the server when called.

The server replaces the current-custodian in order to aid with profiling, so the earlier you start the server during your appโ€™s boot process, the better.

2.2 Client๐Ÿ”—โ„น

 (require debugging/client) package: dbg

The client API may change between versions without warning.

parameter

(current-client) โ†’ client?

(current-client client) โ†’ void?
  client : client?
A parameter that holds the current client.

procedure

(client? v) โ†’ boolean?

  v : any/c
Returns #t when v is a client.

procedure

(connect [#:host host #:port port]) โ†’ client?

  host : string? = "127.0.0.1"
  port : (integer-in 0 65535) = 9011
Connects to the debugging server at the given host and port.

procedure

(connected? [c]) โ†’ boolean?

  c : client? = (current-client)
Returns #t when c is connected.

procedure

(disconnect! [c]) โ†’ void?

  c : client? = (current-client)
Disconnects c from the server.

procedure

(reconnect! [c]) โ†’ void?

  c : client? = (current-client)
Reconnects c to the server.

procedure

(get-info [c]) โ†’ hash?

  c : client? = (current-client)
Gets metadata about the process being debugged.

procedure

(get-memory-use [c]) โ†’ exact-positive-integer?

  c : client? = (current-client)
Gets the number of allocated bytes in use by the process being debugged.

procedure

(get-object-counts [c])

 โ†’ (listof (cons/c string? (cons/c integer? integer?)))
  c : client? = (current-client)
Gets the current number and size (in bytes) of objects alloced by the process being debugged, grouped by type.

procedure

(start-profile [c delay-ms errortrace?]) โ†’ void?

  c : client? = (current-client)
  delay-ms : exact-nonnegative-integer? = 1
  errortrace? : boolean? = #f
Starts a profiling the process being debugged, sampling every delay-ms milliseconds.

The errortrace? argument controls whether or not errortrace is used to construct call stacks. If errortrace was not enabled before starting the process, setting this value to #t will produce empty profiles.

procedure

(stop-profile [c]) โ†’ any/c

  c : client? = (current-client)
Stops the current in-progress profile and returns the profile.

procedure

(get-profile [c]) โ†’ any/c

  c : client? = (current-client)
Gets the last profile from the process being debugged.