~taiite/protodump

ddcf9eef161de1a7dd727be19a46045bfcd0a18f — Hubert Hirtz 1 year, 5 months ago daf3516
Handle functions that do not return anything

They don't have a DW_AT_type attribute
2 files changed, 20 insertions(+), 7 deletions(-)

M src/dwarf.rs
M src/main.rs
M src/dwarf.rs => src/dwarf.rs +13 -5
@@ 21,7 21,7 @@ where

#[derive(Clone, PartialEq)]
pub struct Subprogram<R> {
    pub return_type: types::InstancePtr<R>,
    pub return_type: Option<types::InstancePtr<R>>,
    pub parameters: Option<Vec<Parameter<R>>>,
}



@@ 30,7 30,12 @@ impl types::Comparator {
    where
        R: PartialEq + gimli::Reader,
    {
        if !self.instance_eq(&s1.return_type, &s2.return_type) {
        let return_type_eq = match (&s1.return_type, &s2.return_type) {
            (None, None) => true,
            (Some(r1), Some(r2)) => self.instance_eq(r1, r2),
            _ => false,
        };
        if !return_type_eq {
            return false;
        }
        match (&s1.parameters, &s2.parameters) {


@@ 235,11 240,10 @@ where

                let name = entry_name(&dwarf, &unit, entry)?;
                let typ = entry_type(&mut type_cache, &unit, entry)?;
                if name.is_none() || typ.is_none() {
                if name.is_none() {
                    continue;
                }
                let name = name.unwrap();
                let typ = typ.unwrap();
                let mut parameters = Vec::new();

                let prototyped = matches!(


@@ 316,7 320,11 @@ where
                        .collect(),
                    None => vec![],
                };
                if let Some(return_type) = subprogram.return_type.borrow().underlying.clone() {
                if let Some(return_type) = subprogram
                    .return_type
                    .as_ref()
                    .and_then(|r| r.borrow().underlying.clone())
                {
                    if let Some(name) = &return_type.borrow().name {
                        let name = name.to_string_lossy().unwrap().to_string();
                        parameters.push((name, return_type.clone()));

M src/main.rs => src/main.rs +7 -2
@@ 357,11 357,16 @@ fn prototype<'a, 'b>(

impl fmt::Display for Prototype<'_, '_> {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let return_type = self.subprogram.return_type.borrow();
        if Paint::is_enabled() {
            Style::new(self.color).fmt_prefix(f)?;
        }
        write!(f, "{}{}", return_type, return_type.display_padding())?;
        match &self.subprogram.return_type {
            None => write!(f, "void ")?,
            Some(r) => {
                let r = r.borrow();
                write!(f, "{}{}", r, r.display_padding())?;
            }
        }
        write!(f, "{}", Paint::new(self.name.to_string_lossy()).bold())?;
        if Paint::is_enabled() {
            Style::new(self.color).fmt_prefix(f)?;