Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash with SBValue (core dumped) #23

Closed
tetenpapier opened this issue Jun 10, 2022 · 3 comments
Closed

Crash with SBValue (core dumped) #23

tetenpapier opened this issue Jun 10, 2022 · 3 comments

Comments

@tetenpapier
Copy link
Contributor

In some cases, SBValue contains an other struct in value. Example: SBFrame when I want to get the list of registers :

for r in target.process().selected_thread().selected_frame().registers().iter() {
     println!("SBValue : {:?}", r); // ok
     println!("SBValue name : {:?}", r.name()); // ok
     println!("SBValue value : {:?}", r.value()); // crash
}

I think it's due to return type (&str).

@waywardmonkeys
Copy link
Contributor

Yes, this should probably be Option<&str> or even Option<String> ... if the SBValue doesn't have an associated underlying value, then the result of SBValue::GetValue will be nullptr:

const char *SBValue::GetValue() {
  LLDB_RECORD_METHOD_NO_ARGS(const char *, SBValue, GetValue);

  const char *cstr = nullptr;
  ValueLocker locker;
  lldb::ValueObjectSP value_sp(GetSP(locker));
  if (value_sp) {
    cstr = value_sp->GetValueAsCString();
  }

  return cstr;
}

On the Rust side, this is what it is doing now:

    pub fn value(&self) -> &str {
        unsafe {
            match CStr::from_ptr(sys::SBValueGetValue(self.raw)).to_str() {
                Ok(s) => s,
                _ => panic!("Invalid string?"),
            }
        }
    }

So that clearly should be handling the nullptr case there and returning an Option.

@tetenpapier
Copy link
Contributor Author

Ok, I see. The value isn't set in ValueObjectRegisterSet. However, when I print a register set, I get something in value and I don't understand why. Is it because of pointer in C++ ?

SBValue : SBValue { General Purpose Registers = {                                                                                                                                                                                           
  rax = 0x0000000000000000                                                                                                                                                                                                                  
  rbx = 0x0000000000000000                                                                                                                                                                                                                  
  rcx = 0x0000000000000000                                                                                                                                                                                                                  
  rdx = 0x0000000000000000
//...
}

@tetenpapier
Copy link
Contributor Author

Ok, I've understood where was my error. I've patched the crate and I'll make a PR with new bindings soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants