Compare commits

..

No commits in common. "97fa9927420b6abd204018638d383445f99eb73d" and "41c391ef0cfa75358493485f7ff81bc64c183965" have entirely different histories.

1 changed files with 23 additions and 26 deletions

View File

@ -1421,9 +1421,9 @@ struct AnonUnionGroup {
}
fn get_anon_unions(info: &DwarfInfo, members: &[StructureMember]) -> Result<Vec<AnonUnion>> {
let mut unions = Vec::<AnonUnion>::new();
let mut unions = Vec::new();
let mut offset = u32::MAX;
'member: for (prev, member) in members.iter().skip(1).enumerate() {
for (prev, member) in members.iter().skip(1).enumerate() {
if let Some(bit) = &member.bit {
if bit.bit_offset != 0 {
continue;
@ -1433,11 +1433,6 @@ fn get_anon_unions(info: &DwarfInfo, members: &[StructureMember]) -> Result<Vec<
offset = member.offset;
for (i, member) in members.iter().enumerate() {
if member.offset == offset {
for anon in &unions {
if anon.member_index == i {
continue 'member;
}
}
unions.push(AnonUnion { offset, member_index: i, member_count: 0 });
break;
}
@ -1455,7 +1450,8 @@ fn get_anon_unions(info: &DwarfInfo, members: &[StructureMember]) -> Result<Vec<
anon.member_count = i;
}
}
let mut max_offset = 0;
let mut cur_size = 0;
let mut max_size = 0;
for member in members.iter().skip(anon.member_index).take(anon.member_count + 1) {
if let Some(bit) = &member.bit {
if bit.bit_offset != 0 {
@ -1464,15 +1460,24 @@ fn get_anon_unions(info: &DwarfInfo, members: &[StructureMember]) -> Result<Vec<
}
let size =
if let Some(size) = member.byte_size { size } else { member.kind.size(info)? };
max_offset = max(max_offset, member.offset + size);
if member.offset == anon.offset {
cur_size = size;
} else {
cur_size += size;
}
max_size = max(max_size, cur_size);
}
cur_size = 0;
for member in members.iter().skip(anon.member_index + anon.member_count) {
if let Some(bit) = &member.bit {
if bit.bit_offset != 0 {
continue;
}
}
if member.offset >= max_offset || member.offset < anon.offset {
let size =
if let Some(size) = member.byte_size { size } else { member.kind.size(info)? };
cur_size += size;
if cur_size > max_size {
break;
}
anon.member_count += 1;
@ -1564,8 +1569,8 @@ pub fn struct_def_string(
let mut indent = 4;
let unions = get_anon_unions(info, &t.members)?;
let groups = get_anon_union_groups(&t.members, &unions);
let mut in_union = 0;
let mut in_group = 0;
let mut in_union = false;
let mut in_group = false;
for (i, member) in t.members.iter().enumerate() {
if vis != member.visibility {
vis = member.visibility;
@ -1579,34 +1584,28 @@ pub fn struct_def_string(
if i == anon.member_index + anon.member_count {
indent -= 4;
out.push_str(&indent_all_by(indent, "};\n"));
in_group -= 1;
in_group = false;
}
}
for anon in &unions {
if anon.member_count < 2 {
continue;
}
if i == anon.member_index + anon.member_count {
indent -= 4;
out.push_str(&indent_all_by(indent, "};\n"));
in_union -= 1;
in_union = false;
}
}
for anon in &unions {
if anon.member_count < 2 {
continue;
}
if i == anon.member_index {
out.push_str(&indent_all_by(indent, "union { // inferred\n"));
indent += 4;
in_union += 1;
in_union = true;
}
}
for anon in &groups {
if i == anon.member_index {
out.push_str(&indent_all_by(indent, "struct { // inferred\n"));
indent += 4;
in_group += 1;
in_group = true;
}
}
let mut var_out = String::new();
@ -1619,15 +1618,13 @@ pub fn struct_def_string(
writeln!(var_out, "; // offset {:#X}, size {:#X}", member.offset, size)?;
out.push_str(&indent_all_by(indent, var_out));
}
while in_group > 0 {
if in_group {
indent -= 4;
out.push_str(&indent_all_by(indent, "};\n"));
in_group -= 1;
}
while in_union > 0 {
if in_union {
indent -= 4;
out.push_str(&indent_all_by(indent, "};\n"));
in_union -= 1;
}
out.push('}');
Ok(out)