Various clippy fixes. (#403)
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
//! Debug utils for WebAssembly using Cranelift.
|
||||
|
||||
#![allow(clippy::cast_ptr_alignment)]
|
||||
|
||||
use alloc::string::String;
|
||||
use alloc::vec::Vec;
|
||||
use cranelift_codegen::isa::TargetFrontendConfig;
|
||||
@@ -66,9 +68,9 @@ pub fn emit_debugsections_image(
|
||||
vmctx_info: &ModuleVmctxInfo,
|
||||
at: &ModuleAddressMap,
|
||||
ranges: &ValueLabelsRanges,
|
||||
funcs: &Vec<(*const u8, usize)>,
|
||||
funcs: &[(*const u8, usize)],
|
||||
) -> Result<Vec<u8>, Error> {
|
||||
let ref func_offsets = funcs
|
||||
let func_offsets = &funcs
|
||||
.iter()
|
||||
.map(|(ptr, _)| *ptr as u64)
|
||||
.collect::<Vec<u64>>();
|
||||
@@ -79,7 +81,7 @@ pub fn emit_debugsections_image(
|
||||
// Assuming all functions in the same code block, looking min/max of its range.
|
||||
assert!(funcs.len() > 0);
|
||||
let mut segment_body: (usize, usize) = (!0, 0);
|
||||
for (body_ptr, body_len) in funcs.iter() {
|
||||
for (body_ptr, body_len) in funcs {
|
||||
segment_body.0 = ::core::cmp::min(segment_body.0, *body_ptr as usize);
|
||||
segment_body.1 = ::core::cmp::max(segment_body.1, *body_ptr as usize + body_len);
|
||||
}
|
||||
@@ -168,8 +170,7 @@ fn convert_faerie_elf_to_loadable_file(bytes: &mut Vec<u8>, code_ptr: *const u8)
|
||||
// LLDB wants segment with virtual address set, placing them at the end of ELF.
|
||||
let ph_off = bytes.len();
|
||||
if let Some((sh_offset, v_offset, sh_size)) = segment {
|
||||
let mut segment = Vec::with_capacity(0x38);
|
||||
segment.resize(0x38, 0);
|
||||
let segment = vec![0; 0x38];
|
||||
unsafe {
|
||||
*(segment.as_ptr() as *mut u32) = /* PT_LOAD */ 0x1;
|
||||
*(segment.as_ptr().offset(0x8) as *mut u64) = sh_offset;
|
||||
|
||||
@@ -39,7 +39,7 @@ pub(crate) fn clone_die_attributes<'a, R>(
|
||||
context: &DebugInputContext<R>,
|
||||
addr_tr: &'a AddressTransform,
|
||||
frame_info: Option<&FunctionFrameInfo>,
|
||||
unit_encoding: &gimli::Encoding,
|
||||
unit_encoding: gimli::Encoding,
|
||||
out_unit: &mut write::Unit,
|
||||
current_scope_id: write::UnitEntryId,
|
||||
subprogram_range_builder: Option<RangeInfoBuilder>,
|
||||
@@ -58,15 +58,13 @@ where
|
||||
|
||||
let range_info = if let Some(subprogram_range_builder) = subprogram_range_builder {
|
||||
subprogram_range_builder
|
||||
} else if entry.tag() == gimli::DW_TAG_compile_unit {
|
||||
// FIXME currently address_transform operate on a single func range,
|
||||
// once it is fixed we can properly set DW_AT_ranges attribute.
|
||||
// Using for now DW_AT_low_pc = 0.
|
||||
RangeInfoBuilder::Position(0)
|
||||
} else {
|
||||
if entry.tag() == gimli::DW_TAG_compile_unit {
|
||||
// FIXME currently address_transform operate on a single func range,
|
||||
// once it is fixed we can properly set DW_AT_ranges attribute.
|
||||
// Using for now DW_AT_low_pc = 0.
|
||||
RangeInfoBuilder::Position(0)
|
||||
} else {
|
||||
RangeInfoBuilder::from(entry, context, unit_encoding, cu_low_pc)?
|
||||
}
|
||||
RangeInfoBuilder::from(entry, context, unit_encoding, cu_low_pc)?
|
||||
};
|
||||
range_info.build(addr_tr, out_unit, current_scope_id);
|
||||
|
||||
@@ -127,7 +125,7 @@ where
|
||||
let low_pc = 0;
|
||||
let mut locs = context.loclists.locations(
|
||||
r,
|
||||
*unit_encoding,
|
||||
unit_encoding,
|
||||
low_pc,
|
||||
&context.debug_addr,
|
||||
context.debug_addr_base,
|
||||
@@ -190,7 +188,7 @@ where
|
||||
if let Some(scope_ranges) = scope_ranges {
|
||||
let exprs =
|
||||
expr.build_with_locals(scope_ranges, addr_tr, frame_info, endian);
|
||||
if exprs.len() == 0 {
|
||||
if exprs.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let found_single_expr = {
|
||||
|
||||
@@ -176,7 +176,7 @@ impl CompiledExpression {
|
||||
if let [CompiledExpressionPart::Code(_)] = self.parts.as_slice() {
|
||||
true
|
||||
} else {
|
||||
self.parts.len() == 0
|
||||
self.parts.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ impl CompiledExpression {
|
||||
frame_info: Option<&FunctionFrameInfo>,
|
||||
endian: gimli::RunTimeEndian,
|
||||
) -> alloc::vec::Vec<(write::Address, u64, write::Expression)> {
|
||||
if scope.len() == 0 {
|
||||
if scope.is_empty() {
|
||||
return vec![];
|
||||
}
|
||||
|
||||
@@ -286,13 +286,13 @@ impl CompiledExpression {
|
||||
));
|
||||
}
|
||||
|
||||
return result;
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
pub fn compile_expression<R>(
|
||||
expr: &Expression<R>,
|
||||
encoding: &gimli::Encoding,
|
||||
encoding: gimli::Encoding,
|
||||
frame_base: Option<&CompiledExpression>,
|
||||
) -> Result<Option<CompiledExpression>, Error>
|
||||
where
|
||||
@@ -326,7 +326,7 @@ where
|
||||
parts.push(CompiledExpressionPart::Local(label));
|
||||
} else {
|
||||
let pos = pc.offset_from(&expr.0).into_u64() as usize;
|
||||
let op = Operation::parse(&mut pc, &expr.0, *encoding)?;
|
||||
let op = Operation::parse(&mut pc, &expr.0, encoding)?;
|
||||
match op {
|
||||
Operation::Literal { .. } | Operation::PlusConstant { .. } => (),
|
||||
Operation::StackValue => {
|
||||
|
||||
@@ -43,7 +43,7 @@ pub(crate) fn clone_line_program<R>(
|
||||
unit: &Unit<R, R::Offset>,
|
||||
root: &DebuggingInformationEntry<R>,
|
||||
addr_tr: &AddressTransform,
|
||||
out_encoding: &gimli::Encoding,
|
||||
out_encoding: gimli::Encoding,
|
||||
debug_str: &DebugStr<R>,
|
||||
debug_line: &DebugLine<R>,
|
||||
out_strings: &mut write::StringTable,
|
||||
@@ -89,7 +89,7 @@ where
|
||||
line_range: header.line_range(),
|
||||
};
|
||||
let mut out_program = write::LineProgram::new(
|
||||
*out_encoding,
|
||||
out_encoding,
|
||||
line_encoding,
|
||||
out_comp_dir,
|
||||
out_comp_name,
|
||||
|
||||
@@ -90,7 +90,7 @@ pub fn transform_dwarf(
|
||||
&context,
|
||||
&addr_tr,
|
||||
&ranges,
|
||||
&out_encoding,
|
||||
out_encoding,
|
||||
&vmctx_info,
|
||||
&mut out_units,
|
||||
&mut out_strings,
|
||||
@@ -104,7 +104,7 @@ pub fn transform_dwarf(
|
||||
&vmctx_info,
|
||||
&ranges,
|
||||
&translated,
|
||||
&out_encoding,
|
||||
out_encoding,
|
||||
&mut out_units,
|
||||
&mut out_strings,
|
||||
)?;
|
||||
|
||||
@@ -24,7 +24,7 @@ impl RangeInfoBuilder {
|
||||
pub(crate) fn from<R>(
|
||||
entry: &DebuggingInformationEntry<R>,
|
||||
context: &DebugInputContext<R>,
|
||||
unit_encoding: &gimli::Encoding,
|
||||
unit_encoding: gimli::Encoding,
|
||||
cu_low_pc: u64,
|
||||
) -> Result<Self, Error>
|
||||
where
|
||||
@@ -53,7 +53,7 @@ impl RangeInfoBuilder {
|
||||
pub(crate) fn from_ranges_ref<R>(
|
||||
ranges: RangeListsOffset,
|
||||
context: &DebugInputContext<R>,
|
||||
unit_encoding: &gimli::Encoding,
|
||||
unit_encoding: gimli::Encoding,
|
||||
cu_low_pc: u64,
|
||||
) -> Result<Self, Error>
|
||||
where
|
||||
@@ -61,7 +61,7 @@ impl RangeInfoBuilder {
|
||||
{
|
||||
let mut ranges = context.rnglists.ranges(
|
||||
ranges,
|
||||
*unit_encoding,
|
||||
unit_encoding,
|
||||
cu_low_pc,
|
||||
&context.debug_addr,
|
||||
context.debug_addr_base,
|
||||
@@ -74,17 +74,17 @@ impl RangeInfoBuilder {
|
||||
result.push((range.begin, range.end));
|
||||
}
|
||||
|
||||
return Ok(if result.len() > 0 {
|
||||
Ok(if result.len() > 0 {
|
||||
RangeInfoBuilder::Ranges(result)
|
||||
} else {
|
||||
RangeInfoBuilder::Undefined
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn from_subprogram_die<R>(
|
||||
entry: &DebuggingInformationEntry<R>,
|
||||
context: &DebugInputContext<R>,
|
||||
unit_encoding: &gimli::Encoding,
|
||||
unit_encoding: gimli::Encoding,
|
||||
addr_tr: &AddressTransform,
|
||||
cu_low_pc: u64,
|
||||
) -> Result<Self, Error>
|
||||
@@ -99,7 +99,7 @@ impl RangeInfoBuilder {
|
||||
{
|
||||
let mut ranges = context.rnglists.ranges(
|
||||
r,
|
||||
*unit_encoding,
|
||||
unit_encoding,
|
||||
cu_low_pc,
|
||||
&context.debug_addr,
|
||||
context.debug_addr_base,
|
||||
|
||||
@@ -21,7 +21,7 @@ const PRODUCER_NAME: &str = "wasmtime";
|
||||
fn generate_line_info(
|
||||
addr_tr: &AddressTransform,
|
||||
translated: &HashSet<u32>,
|
||||
out_encoding: &gimli::Encoding,
|
||||
out_encoding: gimli::Encoding,
|
||||
w: &WasmFileInfo,
|
||||
comp_dir_id: write::StringId,
|
||||
name_id: write::StringId,
|
||||
@@ -33,7 +33,7 @@ fn generate_line_info(
|
||||
let line_encoding = LineEncoding::default();
|
||||
|
||||
let mut out_program = write::LineProgram::new(
|
||||
*out_encoding,
|
||||
out_encoding,
|
||||
line_encoding,
|
||||
out_comp_dir,
|
||||
out_comp_name,
|
||||
@@ -181,7 +181,7 @@ fn generate_vars(
|
||||
) {
|
||||
let vmctx_label = get_vmctx_value_label();
|
||||
|
||||
for (label, _range) in frame_info.value_ranges {
|
||||
for label in frame_info.value_ranges.keys() {
|
||||
if label.index() == vmctx_label.index() {
|
||||
append_vmctx_info(
|
||||
unit,
|
||||
@@ -206,7 +206,7 @@ fn generate_vars(
|
||||
let loc_list_id = {
|
||||
let endian = gimli::RunTimeEndian::Little;
|
||||
|
||||
let expr = CompiledExpression::from_label(label.clone());
|
||||
let expr = CompiledExpression::from_label(*label);
|
||||
let mut locs = Vec::new();
|
||||
for (begin, length, data) in
|
||||
expr.build_with_locals(scope_ranges, addr_tr, Some(frame_info), endian)
|
||||
@@ -254,7 +254,7 @@ pub fn generate_simulated_dwarf(
|
||||
vmctx_info: &ModuleVmctxInfo,
|
||||
ranges: &ValueLabelsRanges,
|
||||
translated: &HashSet<u32>,
|
||||
out_encoding: &gimli::Encoding,
|
||||
out_encoding: gimli::Encoding,
|
||||
out_units: &mut write::UnitTable,
|
||||
out_strings: &mut write::StringTable,
|
||||
) -> Result<(), Error> {
|
||||
@@ -288,7 +288,7 @@ pub fn generate_simulated_dwarf(
|
||||
name,
|
||||
)?;
|
||||
|
||||
let unit_id = out_units.add(write::Unit::new(*out_encoding, out_program));
|
||||
let unit_id = out_units.add(write::Unit::new(out_encoding, out_program));
|
||||
let unit = out_units.get_mut(unit_id);
|
||||
|
||||
let root_id = unit.root();
|
||||
|
||||
@@ -157,7 +157,7 @@ pub(crate) fn clone_unit<'a, R>(
|
||||
context: &DebugInputContext<R>,
|
||||
addr_tr: &'a AddressTransform,
|
||||
value_ranges: &'a ValueLabelsRanges,
|
||||
out_encoding: &gimli::Encoding,
|
||||
out_encoding: gimli::Encoding,
|
||||
module_info: &ModuleVmctxInfo,
|
||||
out_units: &mut write::UnitTable,
|
||||
out_strings: &mut write::StringTable,
|
||||
@@ -186,7 +186,7 @@ where
|
||||
)?;
|
||||
|
||||
if entry.tag() == gimli::DW_TAG_compile_unit {
|
||||
let unit_id = out_units.add(write::Unit::new(*out_encoding, out_line_program));
|
||||
let unit_id = out_units.add(write::Unit::new(out_encoding, out_line_program));
|
||||
let comp_unit = out_units.get_mut(unit_id);
|
||||
|
||||
let root_id = comp_unit.root();
|
||||
@@ -206,7 +206,7 @@ where
|
||||
context,
|
||||
addr_tr,
|
||||
None,
|
||||
&unit.encoding(),
|
||||
unit.encoding(),
|
||||
comp_unit,
|
||||
root_id,
|
||||
None,
|
||||
@@ -263,7 +263,7 @@ where
|
||||
let range_builder = RangeInfoBuilder::from_subprogram_die(
|
||||
entry,
|
||||
context,
|
||||
&unit.encoding(),
|
||||
unit.encoding(),
|
||||
addr_tr,
|
||||
cu_low_pc,
|
||||
)?;
|
||||
@@ -285,7 +285,7 @@ where
|
||||
let ranges = entry.attr_value(gimli::DW_AT_ranges)?;
|
||||
if high_pc.is_some() || ranges.is_some() {
|
||||
let range_builder =
|
||||
RangeInfoBuilder::from(entry, context, &unit.encoding(), cu_low_pc)?;
|
||||
RangeInfoBuilder::from(entry, context, unit.encoding(), cu_low_pc)?;
|
||||
current_scope_ranges.push(new_stack_len, range_builder.get_ranges(addr_tr));
|
||||
Some(range_builder)
|
||||
} else {
|
||||
@@ -302,7 +302,7 @@ where
|
||||
}
|
||||
|
||||
if let Some(AttributeValue::Exprloc(expr)) = entry.attr_value(gimli::DW_AT_frame_base)? {
|
||||
if let Some(expr) = compile_expression(&expr, &unit.encoding(), None)? {
|
||||
if let Some(expr) = compile_expression(&expr, unit.encoding(), None)? {
|
||||
current_frame_base.push(new_stack_len, expr);
|
||||
}
|
||||
}
|
||||
@@ -339,7 +339,7 @@ where
|
||||
context,
|
||||
addr_tr,
|
||||
current_value_range.top(),
|
||||
&unit.encoding(),
|
||||
unit.encoding(),
|
||||
&mut comp_unit,
|
||||
die_id,
|
||||
range_builder,
|
||||
|
||||
Reference in New Issue
Block a user