Can I set an LLDB breakpoint when multiple Rust source files share the same name?

白昼怎懂夜的黑 提交于 2021-02-07 12:55:25

问题


Background: In Rust, you typically have multiple source files called mod.rs. For example:

app_name
  src
    main.rs
    foo
      mod.rs
    bar
      mod.rs

Problem: I can't find a way to distinguish one mod.rs from another when setting an LLDB breakpoint:

$ cargo build
$ rust-lldb target/debug/app_name

(lldb) breakpoint set -f mod.rs -l 10
Breakpoint 1: 2 locations.

(lldb) breakpoint set -f foo/mod.rs -l 10
Breakpoint 2: no locations (pending).
WARNING:  Unable to resolve breakpoint to any actual locations.

(lldb) breakpoint set -f src/foo/mod.rs -l 10
Breakpoint 3: no locations (pending).
WARNING:  Unable to resolve breakpoint to any actual locations.

This issue arises most commonly with mod.rs. More generally, it arises anytime multiple source files share the same name.

Question: Is there a way to set a breakpoint at line 10 of foo/mod.rs but not at line 10 of bar/mod.rs?


回答1:


You can use the absolute path to the file. In my case, I compiled in the /tmp directory on OS X, which is actually /private/tmp. That means that I can do something like this:

breakpoint set --file /private/tmp/debug/src/bar/mod.rs --line 2

I figured this out by looking at the DWARF debugging information:

dwarfdump target/debug/debug.dSYM/Contents/Resources/DWARF/debug | grep mod.rs

There are also a few workarounds if this doesn't work:

  1. Break at a function instead: breakpoint set --name my_func. It's unlikely that you will have the same method name, but here you can use the module name as well: breakpoint set --name foo::my_func.

  2. Disable non-interesting duplicate breakpoints. breakpoint set establishes a logical breakpoint with a numeric ID (like 1), and then real breakpoints that match the condition have a sub ID (like 1.1). You can see these with breakpoint list and then disable others with breakpoint disable 1.1.



来源:https://stackoverflow.com/questions/34859936/can-i-set-an-lldb-breakpoint-when-multiple-rust-source-files-share-the-same-name

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!