本文介绍了当多个Rust源文件共享相同的名称时,是否可以设置LLDB断点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

背景:在Rust中,通常有多个名为 mod.rs 的源文件.例如:

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

问题:我找不到设置LLDB断点时将一个 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.

此问题最常见于 mod.rs .通常,只要多个源文件共享相同的名称,就会出现这种情况.

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

问题:是否可以在 foo/mod.rs 的第10行设置断点,但不能在 bar/mod.rs的第10行设置断点?

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?

推荐答案

您可以使用文件的绝对路径.就我而言,我在OS X的/tmp 目录中进行编译,该目录实际上是/private/tmp .那意味着我可以做这样的事情:

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

我通过查看DWARF调试信息了解了这一点:

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. 在函数处中断: breakpoint set --name my_func .您不太可能拥有相同的方法名称,但是在这里您也可以使用模块名称: breakpoint set --name foo :: my_func .

  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.

禁用无趣的重复断点. breakpoint set 建立具有数字ID(例如 1 )的逻辑断点,然后与条件匹配的实际断点具有子ID(例如 1.1 ).您可以使用 breakpoint list 查看这些,然后使用 breakpoint disable 1.1 禁用其他.

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.

这篇关于当多个Rust源文件共享相同的名称时,是否可以设置LLDB断点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 12:22