Browse Source

add experimental gdb debug lib

tags/pre-alpha-0.0
Manos Pitsidianakis 3 months ago
parent
commit
865c9a6bef
No known key found for this signature in database
4 changed files with 96 additions and 1 deletions
  1. 35
    0
      .gdbinit
  2. 1
    1
      Cargo.toml
  3. 16
    0
      debug_printer/Cargo.toml
  4. 44
    0
      debug_printer/src/lib.rs

+ 35
- 0
.gdbinit View File

@@ -5,3 +5,38 @@ break core::option::expect_failed::h4927e1fef06c4878
break core::panicking::panic
break libcore/panicking.rs:58
break libcore/result.rs:945
set auto-load python-scripts
break melib/src/mailbox/thread.rs:1010
set print thread-events off

#python
#import os
#import sys
#
#sys.path.insert(0, os.getcwd() + '/scripts/gdb_meli/')
#import gdb
#import gdb_meli
#
#print(gdb_meli.__file__)
#
#help(gdb_meli)
##from gdb_meli import build_pretty_printer
##print(gdb.objfiles()[0].filename)
##gdb_meli.register_pretty_printer(gdb)
##gdb.printing.register_pretty_printer(
## gdb.current_objfile(),
## gdb_meli.build_pretty_printer())
#end
python

import sys, os

sys.path.insert(0, os.getcwd() + '/scripts/gdb_meli/')


import gdb_meli, gdb
#gdb_meli.register_meli_printers(gdb)
#gdb.printing.register_pretty_printer(
# gdb.current_objfile(),
# gdb_meli.build_meli_printer())
end

+ 1
- 1
Cargo.toml View File

@@ -21,4 +21,4 @@ lto = true
debug = true

[workspace]
members = ["melib", "ui"]
members = ["melib", "ui", "debug_printer"]

+ 16
- 0
debug_printer/Cargo.toml View File

@@ -0,0 +1,16 @@
[package]
name = "debug_printer"
version = "0.0.1" #:version
authors = []
workspace = ".."

[lib]
name = "debugprinter"
crate-type = ["dylib"]
path = "src/lib.rs"


[dependencies]
libc = {version = "0.2.55", features = ["extra_traits",] }
melib = { path = "../melib", version = "*" }
ui = { path = "../ui", version = "*" }

+ 44
- 0
debug_printer/src/lib.rs View File

@@ -0,0 +1,44 @@
extern crate libc;
extern crate melib;

use melib::Envelope;
use std::ffi::CString;
use std::os::raw::c_char;

#[no_mangle]
pub extern "C" fn print_envelope(ptr: *const Envelope) -> *const c_char {
unsafe {
assert!(!ptr.is_null(), "Null pointer in print_envelope");
//println!("got addr {}", p as u64);
//unsafe { CString::new("blah".to_string()).unwrap().as_ptr() }
let s = CString::new(format!("{:?}", *ptr)).unwrap();
drop(ptr);
let p = s.as_ptr();
std::mem::forget(s);
p
}
}

#[no_mangle]
pub extern "C" fn get_empty_envelope() -> *mut Envelope {
let mut ret = Envelope::default();
let ptr = std::ptr::NonNull::new(&mut ret as *mut Envelope)
.expect("Envelope::default() has a NULL pointer?");

let ptr = ptr.as_ptr();
std::mem::forget(ret);
ptr
}

#[no_mangle]
pub extern "C" fn destroy_cstring(ptr: *mut c_char) {
unsafe {
let slice = CString::from_raw(ptr);
drop(slice);
}
}

#[no_mangle]
pub extern "C" fn envelope_size() -> libc::size_t {
std::mem::size_of::<Envelope>()
}

Loading…
Cancel
Save