Removes panic! from the debug crate. (#1261)
This commit is contained in:
@@ -3,7 +3,7 @@ use super::expression::{compile_expression, CompiledExpression, FunctionFrameInf
|
||||
use super::range_info_builder::RangeInfoBuilder;
|
||||
use super::refs::{PendingDebugInfoRefs, PendingUnitRefs};
|
||||
use super::{DebugInputContext, Reader, TransformError};
|
||||
use anyhow::Error;
|
||||
use anyhow::{bail, Error};
|
||||
use gimli::{write, AttributeValue, DebugLineOffset, DebugStr, DebuggingInformationEntry};
|
||||
use wasmtime_environ::isa::TargetIsa;
|
||||
|
||||
@@ -143,7 +143,7 @@ where
|
||||
addr_tr,
|
||||
frame_info,
|
||||
endian,
|
||||
) {
|
||||
)? {
|
||||
if len == 0 {
|
||||
// Ignore empty range
|
||||
continue;
|
||||
@@ -183,7 +183,7 @@ where
|
||||
// Conversion to loclist is required.
|
||||
if let Some(scope_ranges) = scope_ranges {
|
||||
let exprs =
|
||||
expr.build_with_locals(scope_ranges, addr_tr, frame_info, endian);
|
||||
expr.build_with_locals(scope_ranges, addr_tr, frame_info, endian)?;
|
||||
if exprs.is_empty() {
|
||||
continue;
|
||||
}
|
||||
@@ -252,7 +252,7 @@ where
|
||||
pending_di_refs.insert(current_scope_id, attr.name(), offset);
|
||||
continue;
|
||||
}
|
||||
_ => panic!(), //write::AttributeValue::StringRef(out_strings.add("_")),
|
||||
a => bail!("Unexpected attribute: {:?}", a),
|
||||
};
|
||||
let current_scope = out_unit.get_mut(current_scope_id);
|
||||
current_scope.set(attr.name(), attr_value);
|
||||
@@ -265,7 +265,7 @@ pub(crate) fn clone_attr_string<R>(
|
||||
form: gimli::DwForm,
|
||||
debug_str: &DebugStr<R>,
|
||||
out_strings: &mut write::StringTable,
|
||||
) -> Result<write::LineString, gimli::Error>
|
||||
) -> Result<write::LineString, Error>
|
||||
where
|
||||
R: Reader,
|
||||
{
|
||||
@@ -274,7 +274,7 @@ where
|
||||
debug_str.get_str(*str_offset)?.to_slice()?.to_vec()
|
||||
}
|
||||
AttributeValue::String(b) => b.to_slice()?.to_vec(),
|
||||
_ => panic!("Unexpected attribute value"),
|
||||
v => bail!("Unexpected attribute value: {:?}", v),
|
||||
};
|
||||
Ok(match form {
|
||||
gimli::DW_FORM_strp => {
|
||||
@@ -282,6 +282,6 @@ where
|
||||
write::LineString::StringRef(id)
|
||||
}
|
||||
gimli::DW_FORM_string => write::LineString::String(content),
|
||||
_ => panic!("DW_FORM_line_strp or other not supported"),
|
||||
_ => bail!("DW_FORM_line_strp or other not supported"),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::address_transform::AddressTransform;
|
||||
use anyhow::Error;
|
||||
use anyhow::{bail, Context, Error, Result};
|
||||
use gimli::{self, write, Expression, Operation, Reader, ReaderOffset, Register, X86_64};
|
||||
use more_asserts::{assert_le, assert_lt};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
@@ -70,7 +70,7 @@ impl<'a> CompiledExpression<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn map_reg(isa: &dyn TargetIsa, reg: RegUnit) -> Register {
|
||||
fn map_reg(isa: &dyn TargetIsa, reg: RegUnit) -> Result<Register> {
|
||||
// TODO avoid duplication with fde.rs
|
||||
assert!(isa.name() == "x86" && isa.pointer_bits() == 64);
|
||||
// Mapping from https://github.com/bytecodealliance/cranelift/pull/902 by @iximeow
|
||||
@@ -116,11 +116,11 @@ fn map_reg(isa: &dyn TargetIsa, reg: RegUnit) -> Register {
|
||||
"IntRegs" => {
|
||||
// x86 GP registers have a weird mapping to DWARF registers, so we use a
|
||||
// lookup table.
|
||||
X86_GP_REG_MAP[(reg - bank.first_unit) as usize]
|
||||
Ok(X86_GP_REG_MAP[(reg - bank.first_unit) as usize])
|
||||
}
|
||||
"FloatRegs" => X86_XMM_REG_MAP[(reg - bank.first_unit) as usize],
|
||||
_ => {
|
||||
panic!("unsupported register bank: {}", bank.name);
|
||||
"FloatRegs" => Ok(X86_XMM_REG_MAP[(reg - bank.first_unit) as usize]),
|
||||
bank_name => {
|
||||
bail!("unsupported register bank: {}", bank_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -129,22 +129,18 @@ fn translate_loc(
|
||||
loc: ValueLoc,
|
||||
frame_info: Option<&FunctionFrameInfo>,
|
||||
isa: &dyn TargetIsa,
|
||||
) -> Option<Vec<u8>> {
|
||||
) -> Result<Option<Vec<u8>>> {
|
||||
use gimli::write::Writer;
|
||||
match loc {
|
||||
Ok(match loc {
|
||||
ValueLoc::Reg(reg) => {
|
||||
let machine_reg = map_reg(isa, reg).0 as u8;
|
||||
let machine_reg = map_reg(isa, reg)?.0 as u8;
|
||||
Some(if machine_reg < 32 {
|
||||
vec![gimli::constants::DW_OP_reg0.0 + machine_reg]
|
||||
} else {
|
||||
let endian = gimli::RunTimeEndian::Little;
|
||||
let mut writer = write::EndianVec::new(endian);
|
||||
writer
|
||||
.write_u8(gimli::constants::DW_OP_regx.0 as u8)
|
||||
.expect("regx");
|
||||
writer
|
||||
.write_uleb128(machine_reg.into())
|
||||
.expect("machine_reg");
|
||||
writer.write_u8(gimli::constants::DW_OP_regx.0 as u8)?;
|
||||
writer.write_uleb128(machine_reg.into())?;
|
||||
writer.into_vec()
|
||||
})
|
||||
}
|
||||
@@ -153,21 +149,17 @@ fn translate_loc(
|
||||
if let Some(ss_offset) = frame_info.stack_slots[ss].offset {
|
||||
let endian = gimli::RunTimeEndian::Little;
|
||||
let mut writer = write::EndianVec::new(endian);
|
||||
writer
|
||||
.write_u8(gimli::constants::DW_OP_breg0.0 + X86_64::RBP.0 as u8)
|
||||
.expect("bp wr");
|
||||
writer.write_sleb128(ss_offset as i64 + 16).expect("ss wr");
|
||||
writer
|
||||
.write_u8(gimli::constants::DW_OP_deref.0 as u8)
|
||||
.expect("bp wr");
|
||||
writer.write_u8(gimli::constants::DW_OP_breg0.0 + X86_64::RBP.0 as u8)?;
|
||||
writer.write_sleb128(ss_offset as i64 + 16)?;
|
||||
writer.write_u8(gimli::constants::DW_OP_deref.0 as u8)?;
|
||||
let buf = writer.into_vec();
|
||||
return Some(buf);
|
||||
return Ok(Some(buf));
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn append_memory_deref(
|
||||
@@ -176,13 +168,13 @@ fn append_memory_deref(
|
||||
vmctx_loc: ValueLoc,
|
||||
endian: gimli::RunTimeEndian,
|
||||
isa: &dyn TargetIsa,
|
||||
) -> write::Result<bool> {
|
||||
) -> Result<bool> {
|
||||
use gimli::write::Writer;
|
||||
let mut writer = write::EndianVec::new(endian);
|
||||
// FIXME for imported memory
|
||||
match vmctx_loc {
|
||||
ValueLoc::Reg(vmctx_reg) => {
|
||||
let reg = map_reg(isa, vmctx_reg);
|
||||
let reg = map_reg(isa, vmctx_reg)?;
|
||||
writer.write_u8(gimli::constants::DW_OP_breg0.0 + reg.0 as u8)?;
|
||||
let memory_offset = match frame_info.vmctx_memory_offset() {
|
||||
Some(offset) => offset,
|
||||
@@ -248,9 +240,9 @@ impl<'a> CompiledExpression<'a> {
|
||||
addr_tr: &AddressTransform,
|
||||
frame_info: Option<&FunctionFrameInfo>,
|
||||
endian: gimli::RunTimeEndian,
|
||||
) -> Vec<(write::Address, u64, write::Expression)> {
|
||||
) -> Result<Vec<(write::Address, u64, write::Expression)>> {
|
||||
if scope.is_empty() {
|
||||
return vec![];
|
||||
return Ok(vec![]);
|
||||
}
|
||||
|
||||
if let [CompiledExpressionPart::Code(code)] = self.parts.as_slice() {
|
||||
@@ -260,7 +252,7 @@ impl<'a> CompiledExpression<'a> {
|
||||
result_scope.push((addr, len, write::Expression(code.to_vec())));
|
||||
}
|
||||
}
|
||||
return result_scope;
|
||||
return Ok(result_scope);
|
||||
}
|
||||
|
||||
let vmctx_label = get_vmctx_value_label();
|
||||
@@ -295,8 +287,8 @@ impl<'a> CompiledExpression<'a> {
|
||||
match part {
|
||||
CompiledExpressionPart::Code(c) => code_buf.extend_from_slice(c.as_slice()),
|
||||
CompiledExpressionPart::Local(label) => {
|
||||
let loc = *label_location.get(&label).expect("loc");
|
||||
if let Some(expr) = translate_loc(loc, frame_info, self.isa) {
|
||||
let loc = *label_location.get(&label).context("label_location")?;
|
||||
if let Some(expr) = translate_loc(loc, frame_info, self.isa)? {
|
||||
code_buf.extend_from_slice(&expr)
|
||||
} else {
|
||||
continue 'range;
|
||||
@@ -312,9 +304,7 @@ impl<'a> CompiledExpression<'a> {
|
||||
*vmctx_loc,
|
||||
endian,
|
||||
self.isa,
|
||||
)
|
||||
.expect("append_memory_deref")
|
||||
{
|
||||
)? {
|
||||
continue 'range;
|
||||
}
|
||||
} else {
|
||||
@@ -327,9 +317,13 @@ impl<'a> CompiledExpression<'a> {
|
||||
if let (Some(vmctx_loc), Some(frame_info)) =
|
||||
(label_location.get(&vmctx_label), frame_info)
|
||||
{
|
||||
if !append_memory_deref(&mut code_buf, frame_info, *vmctx_loc, endian, self.isa)
|
||||
.expect("append_memory_deref")
|
||||
{
|
||||
if !append_memory_deref(
|
||||
&mut code_buf,
|
||||
frame_info,
|
||||
*vmctx_loc,
|
||||
endian,
|
||||
self.isa,
|
||||
)? {
|
||||
continue 'range;
|
||||
}
|
||||
} else {
|
||||
@@ -346,7 +340,7 @@ impl<'a> CompiledExpression<'a> {
|
||||
));
|
||||
}
|
||||
|
||||
result
|
||||
Ok(result)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use super::address_transform::AddressTransform;
|
||||
use super::attr::clone_attr_string;
|
||||
use super::{Reader, TransformError};
|
||||
use anyhow::Error;
|
||||
use anyhow::{Context, Error};
|
||||
use gimli::{
|
||||
write, DebugLine, DebugLineOffset, DebugStr, DebuggingInformationEntry, LineEncoding, Unit,
|
||||
};
|
||||
@@ -56,13 +56,13 @@ where
|
||||
let comp_dir = root.attr_value(gimli::DW_AT_comp_dir)?;
|
||||
let comp_name = root.attr_value(gimli::DW_AT_name)?;
|
||||
let out_comp_dir = clone_attr_string(
|
||||
comp_dir.as_ref().expect("comp_dir"),
|
||||
comp_dir.as_ref().context("comp_dir")?,
|
||||
gimli::DW_FORM_strp,
|
||||
debug_str,
|
||||
out_strings,
|
||||
)?;
|
||||
let out_comp_name = clone_attr_string(
|
||||
comp_name.as_ref().expect("comp_name"),
|
||||
comp_name.as_ref().context("comp_name")?,
|
||||
gimli::DW_FORM_strp,
|
||||
debug_str,
|
||||
out_strings,
|
||||
|
||||
@@ -2,7 +2,7 @@ use super::expression::{CompiledExpression, FunctionFrameInfo};
|
||||
use super::utils::{add_internal_types, append_vmctx_info, get_function_frame_info};
|
||||
use super::AddressTransform;
|
||||
use crate::read_debuginfo::WasmFileInfo;
|
||||
use anyhow::Error;
|
||||
use anyhow::{Context, Error};
|
||||
use gimli::write;
|
||||
use gimli::{self, LineEncoding};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
@@ -177,7 +177,7 @@ fn generate_vars(
|
||||
locals_names: Option<&HashMap<u32, String>>,
|
||||
out_strings: &mut write::StringTable,
|
||||
isa: &dyn TargetIsa,
|
||||
) {
|
||||
) -> Result<(), Error> {
|
||||
let vmctx_label = get_vmctx_value_label();
|
||||
|
||||
// Normalize order of ValueLabelsRanges keys to have reproducable results.
|
||||
@@ -195,8 +195,7 @@ fn generate_vars(
|
||||
scope_ranges,
|
||||
out_strings,
|
||||
isa,
|
||||
)
|
||||
.expect("append_vmctx_info success");
|
||||
)?;
|
||||
} else {
|
||||
let var_index = label.index();
|
||||
let (type_die_id, is_param) =
|
||||
@@ -213,7 +212,7 @@ fn generate_vars(
|
||||
let expr = CompiledExpression::from_label(*label, isa);
|
||||
let mut locs = Vec::new();
|
||||
for (begin, length, data) in
|
||||
expr.build_with_locals(scope_ranges, addr_tr, Some(frame_info), endian)
|
||||
expr.build_with_locals(scope_ranges, addr_tr, Some(frame_info), endian)?
|
||||
{
|
||||
locs.push(write::Location::StartLength {
|
||||
begin,
|
||||
@@ -250,6 +249,7 @@ fn generate_vars(
|
||||
);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn generate_simulated_dwarf(
|
||||
@@ -279,8 +279,17 @@ pub fn generate_simulated_dwarf(
|
||||
};
|
||||
|
||||
let (unit, root_id, name_id) = {
|
||||
let comp_dir_id = out_strings.add(path.parent().expect("path dir").to_str().unwrap());
|
||||
let name = path.file_name().expect("path name").to_str().unwrap();
|
||||
let comp_dir_id = out_strings.add(
|
||||
path.parent()
|
||||
.context("path dir")?
|
||||
.to_str()
|
||||
.context("path dir encoding")?,
|
||||
);
|
||||
let name = path
|
||||
.file_name()
|
||||
.context("path name")?
|
||||
.to_str()
|
||||
.context("path name encoding")?;
|
||||
let name_id = out_strings.add(name);
|
||||
|
||||
let out_program = generate_line_info(
|
||||
@@ -370,7 +379,7 @@ pub fn generate_simulated_dwarf(
|
||||
locals_names.and_then(|m| m.get(&(index as u32))),
|
||||
out_strings,
|
||||
isa,
|
||||
);
|
||||
)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ use super::range_info_builder::RangeInfoBuilder;
|
||||
use super::refs::{PendingDebugInfoRefs, PendingUnitRefs, UnitRefsMap};
|
||||
use super::utils::{add_internal_types, append_vmctx_info, get_function_frame_info};
|
||||
use super::{DebugInputContext, Reader, TransformError};
|
||||
use anyhow::Error;
|
||||
use anyhow::{Context, Error};
|
||||
use gimli::write;
|
||||
use gimli::{AttributeValue, DebuggingInformationEntry, Unit};
|
||||
use std::collections::HashSet;
|
||||
@@ -356,7 +356,7 @@ where
|
||||
vmctx_die_id,
|
||||
addr_tr,
|
||||
current_value_range.top(),
|
||||
current_scope_ranges.top().expect("range"),
|
||||
current_scope_ranges.top().context("range")?,
|
||||
out_strings,
|
||||
isa,
|
||||
)?;
|
||||
|
||||
@@ -118,7 +118,7 @@ pub(crate) fn append_vmctx_info(
|
||||
let expr = CompiledExpression::vmctx(isa);
|
||||
let mut locs = Vec::new();
|
||||
for (begin, length, data) in
|
||||
expr.build_with_locals(scope_ranges, addr_tr, frame_info, endian)
|
||||
expr.build_with_locals(scope_ranges, addr_tr, frame_info, endian)?
|
||||
{
|
||||
locs.push(write::Location::StartLength {
|
||||
begin,
|
||||
|
||||
Reference in New Issue
Block a user