admin管理员组

文章数量:1202391

I am using vscode+rust-analyzer+codelldb to debug rust code on Ubuntu server 24.04. I want to easily see values in a Dataframe or Series like what we usually do when debugging python pandas programs, but I can only get in vscode 'variable' window: enter image description here How can I see the values hold in a dataframe or series while debugging?

I tried use dbg! in debug console , only get msg: dbg!(amount) error: 'dbg' is not a valid command.

I posted an issue in polars project, I got the reply: This is really not a Polars specific problem. LLDB has long had problems pretty printing Rust structures. Rust provides a custom script to add pretty printing but I have never really had success with that.

I also tried rustrover, it do not provide the wanted feature.

Here is my test code:

use polars::prelude::*;
use rand::Rng;

fn main() -> Result<(), PolarsError> {
    // Generate sample data with length 15
    let mut rng = rand::thread_rng();

    let amount: Vec<i32> = (0..15).map(|_| rng.gen_range(100..600)).collect();
    let cond: Vec<bool> = (0..15).map(|_| rng.gen_bool(0.3)).collect();

    let amount_series = Series::new("amount", amount);
    let cond_series = Series::new("cond", cond);

    let df = DataFrame::new(vec![
        amount_series,
        cond_series,
    ])?;
    // I know this prints out df, but when debug hit breakpoints here, I can't see the data from vscode debug "variable"  window
    println!("{}", df); 

    Ok(())
}

I am using vscode+rust-analyzer+codelldb to debug rust code on Ubuntu server 24.04. I want to easily see values in a Dataframe or Series like what we usually do when debugging python pandas programs, but I can only get in vscode 'variable' window: enter image description here How can I see the values hold in a dataframe or series while debugging?

I tried use dbg! in debug console , only get msg: dbg!(amount) error: 'dbg' is not a valid command.

I posted an issue in polars project, I got the reply: This is really not a Polars specific problem. LLDB has long had problems pretty printing Rust structures. Rust provides a custom script to add pretty printing https://github.com/rust-lang/rust/blob/master/src/etc/rust-lldb but I have never really had success with that. https://github.com/pola-rs/polars/issues/20803

I also tried rustrover, it do not provide the wanted feature.

Here is my test code:

use polars::prelude::*;
use rand::Rng;

fn main() -> Result<(), PolarsError> {
    // Generate sample data with length 15
    let mut rng = rand::thread_rng();

    let amount: Vec<i32> = (0..15).map(|_| rng.gen_range(100..600)).collect();
    let cond: Vec<bool> = (0..15).map(|_| rng.gen_bool(0.3)).collect();

    let amount_series = Series::new("amount", amount);
    let cond_series = Series::new("cond", cond);

    let df = DataFrame::new(vec![
        amount_series,
        cond_series,
    ])?;
    // I know this prints out df, but when debug hit breakpoints here, I can't see the data from vscode debug "variable"  window
    println!("{}", df); 

    Ok(())
}
Share Improve this question asked Jan 21 at 7:44 Swamp RagerSwamp Rager 1
Add a comment  | 

1 Answer 1

Reset to default 0

lldb does not have native support for the Rust language or the Rust typesystem. That prohibits access to some of lldb's powerful features. For instance, it looks like dbg! is some Rust construct that you want to call. Normally, the way you would access some printing function for values in your program would be to use the lldb expression parser to actually call this function in the debugee:

(lldb) expr dbg!(amount)

However, because there isn't first-class Rust language support for lldb, there isn't a Rust expression parser. To the extent there is Rust support in lldb, it's limited to "telling lldb that Rust is close enough to C++ that you can use the C++ expression parser for Rust types". From what I hear that doesn't work terribly well.

The other support provided - as you mentioned - is that someone has provided some lldb "data formatters" which know how traverse the actual ivars of Rust datatypes and present them in some useful way.

In the current state of things, the data formatters (summary or synthetic child providers) are the main way to augment your view of your Rust datatypes. However, it doesn't seem like there are data formatters for the types you want to view. Depending on how hard the data structures you are interested in are to grok, it might not be too hard to write a formatter for them. That process is described here:

https://lldb.llvm.org/use/variable.html

本文标签: lldbHow can I see the values in dataframe or series when debug rust polars programStack Overflow