liveBook · Manning

Breakpoint

As explained in Rust Web Development

A breakpoint is a specified point in a program's code where execution can be paused for inspection.

A breakpoint marks a location where a debugger pauses a running program. While it is stopped, you can inspect values and the call stack, then continue execution or step through the code. section 6.3 section 6.3.3

For a web service, a breakpoint can help trace a request and check whether the data reaches the expected function. In LLDB, set one by function name or source location, run the program, and inspect its state when execution stops. In Visual Studio Code, click beside a line number; use Step Over to move through subsequent code. section 6.3.2 section 6.3.3

Listing 6.29 Starting our web service via LLDB and using breakpoints
$ cargo build                                                          #1
    Finished dev [unoptimized + debuginfo] target(s) in 0.04s
 
$ lldb target/debug/practical-rust-book                                #2
(lldb) target create "target/debug/practical-rust-book"
Current executable set to '/target/debug/practical-rust-book' (arm64).
(lldb) b add_question                                                  #3
Breakpoint 1: where = practical-rust-... + 48 at question.rs:58:48, 
    address = 0x0000000100102f54
(lldb) breakpoint list                                                 #4
Current breakpoints:
1: name = 'add_question', locations = 1
  1.1: where = practical-rust-... 48 at question.rs:58:48, 
    address = practical-rust-book[0x0000000100102f54], 
    unresolved, hit count = 0
 
(lldb) r                                                               #5
Process 96335 launched: '..../target/debug/practical-rust-book' (arm64)
2022-05-02T17:37:44.327462Z  INFO get_questions request
    {method=POST path=/questions id=8feb7e42-cc15-4bde-a34e-97878c2d3cc4}:
    practical_rust_book: close time.busy=61.0µs time.idle=89.6µs
Process 96335 stopped                                                  #6
* thread #11, name = 'tokio-runtime-worker', stop reason = breakpoint 1.1
    frame #0: 0x0000000100102f54 practical-rust-book`practical_rust_book
        ::routes::question::add_question::hd2aa84941d704842
        (store=Store @ 0x000000017125cee0, 
            question=Question @ 0x000000017125cf28
        ) at question.rs:58:48
   55       pub async fn add_question(
   56           store: Store,
   57           question: Question,
-> 58       ) -> Result<impl warp::Reply, warp::Rejection> {
   59           store
   60               .questions
   61               .write()
Target 0: (practical-rust-book) stopped.
(lldb) frame variable                                                  #7
(practical_rust_book::store::Store) store = {
...
 
  title = {
    vec = {
      buf = {
        ptr = (pointer = "question title", 
       _marker = core::marker::PhantomData<unsigned char> 
            @ 0x000000017125cf40)
        cap = 9
        alloc = {}
      }
      len = 9
    }
  }
  content = {
    vec = {
      buf = {
        ptr = (pointer = "question content", _
        marker = core::marker::PhantomData<unsigned char> 
            @ 0x000000017125cf58)
        cap = 19
        alloc = {}
      }
      len = 19
    }
  }
  tags = {}
}
(lldb) process continue                                                #8
#1 Step 1
#2 Step 2
#3 Step 3
#4 Step 4
#5 Step 5
#6 Step 6
#7 Step 7
#8 Step 8

See an LLDB session that sets a breakpoint in `add_question` while debugging a web service. section 6.3.2

How Rust Web Development covers it

How deep it goes
Explains breakpoint placement, pausing, inspection, and stepping, while noting that debugger features and Rust support are not exhaustive.
Examples
Uses a web-service POST request and an `add_question` function breakpoint to inspect request handling.
What it assumes
Assumes a Rust application and debugger setup; shows CodeLLDB installation and `launch.json` setup for Visual Studio Code.
What you can do after
Debug with LLDB or Visual Studio Code by pausing execution, inspecting variables, and continuing or stepping.
How it connects
Connects breakpoints to debuggers, variable inspection, call stacks, logging, and stepping.

Also explained in

Compare how 8 books explain breakpoint →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Rust Web Development. The section links point to the parts of the book it draws on.