~taiite/protodump

1e4c5978de0ec9adf763779e87165553a9f74cb7 — Hubert Hirtz a month ago d31d7df
Account for (void) argument lists
2 files changed, 34 insertions(+), 13 deletions(-)

M src/dwarf.rs
M src/main.rs
M src/dwarf.rs => src/dwarf.rs +16 -1
@@ 21,7 21,7 @@ where
#[derive(Clone, PartialEq)]
pub struct Subprogram<R> {
    pub return_type: types::InstancePtr<R>,
    pub parameters: Vec<Parameter<R>>,
    pub parameters: Option<Vec<Parameter<R>>>,
}

/// Iterator over the children of an entry.


@@ 219,6 219,11 @@ where
                let typ = typ.unwrap();
                let mut parameters = Vec::new();

                let prototyped = matches!(
                    entry.attr_value(gimli::DW_AT_prototyped)?,
                    Some(gimli::AttributeValue::Flag(true))
                );

                if entry.has_children() {
                    entries.next_dfs()?.unwrap();
                    loop {


@@ 240,6 245,16 @@ where
                    }
                }

                let parameters = if parameters.is_empty() {
                    if prototyped {
                        Some(parameters)
                    } else {
                        None
                    }
                } else {
                    Some(parameters)
                };

                subprograms.insert(
                    name,
                    Subprogram {

M src/main.rs => src/main.rs +18 -12
@@ 222,20 222,26 @@ fn show_prototype(name: Reader<'_>, prototype: &dwarf::Subprogram<Reader<'_>>, c
    } else {
        print!("{}(", name.to_string_lossy());
    }
    let mut first = true;
    for param in &prototype.parameters {
        if first {
            first = false;
        } else {
            print!(", ");
        }
        let type_ = param.type_.borrow();
        print!("{}", type_);
        if let Some(name) = param.name {
            print!("{}{}", type_.display_padding(), name.to_string_lossy());
    match &prototype.parameters {
        None => println!(");"),
        Some(params) if params.is_empty() => println!("void);"),
        Some(params) => {
            let mut first = true;
            for param in params {
                if first {
                    first = false;
                } else {
                    print!(", ");
                }
                let type_ = param.type_.borrow();
                print!("{}", type_);
                if let Some(name) = param.name {
                    print!("{}{}", type_.display_padding(), name.to_string_lossy());
                }
            }
            println!(");");
        }
    }
    println!(");");
}

fn show_prototypes(sources: Sources<'_>) {