|
5 | 5 |
|
6 | 6 | use super::context::{CodeGenError, EbpfContext, Result}; |
7 | 7 | use ghostscope_dwarf::{ |
8 | | - semantics::{add_location_offset, dereference_location}, |
9 | 8 | AddressOrigin, Availability, ComputeStep, EntryValueCase, MemoryAccessSize, PlannedAddress, |
10 | 9 | PlannedAddressKind, SectionType, TypeInfo, VariableAccessPath, VariableAccessSegment, |
11 | 10 | VariableLocation, VariableMaterializationPlan, VariableReadPlan, |
@@ -1227,7 +1226,7 @@ impl<'ctx, 'dw> EbpfContext<'ctx, 'dw> { |
1227 | 1226 | } |
1228 | 1227 |
|
1229 | 1228 | if let Some((global_module, plan)) = analyzer |
1230 | | - .plan_global_chain_access_read_plan(&prefer_module, var_name, &[]) |
| 1229 | + .plan_global_access_read_plan(&prefer_module, var_name, &VariableAccessPath::default()) |
1231 | 1230 | .map_err(|err| CodeGenError::DwarfError(err.to_string()))? |
1232 | 1231 | { |
1233 | 1232 | debug!("Found DWARF global '{}' via variable read plan", var_name); |
@@ -1382,74 +1381,6 @@ impl<'ctx, 'dw> EbpfContext<'ctx, 'dw> { |
1382 | 1381 | }; |
1383 | 1382 | Ok(Some((base, VariableAccessPath::new(segments)))) |
1384 | 1383 | } |
1385 | | - |
1386 | | - /// Compute a typed pointed-to location for expressions like `ptr +/- K` where K is an element index. |
1387 | | - /// Returns a computed location along with the pointed-to DWARF type. |
1388 | | - /// The offset is scaled by the element size of the pointer/array target type. |
1389 | | - pub fn compute_pointed_location_with_index( |
1390 | | - &mut self, |
1391 | | - ptr_expr: &crate::script::Expr, |
1392 | | - index: i64, |
1393 | | - ) -> Result<(VariableLocation, TypeInfo)> { |
1394 | | - use ghostscope_dwarf::TypeInfo; |
1395 | | - |
1396 | | - // Resolve the pointer expression via DWARF |
1397 | | - let ptr_var = self |
1398 | | - .query_dwarf_for_complex_expr(ptr_expr)? |
1399 | | - .ok_or_else(|| CodeGenError::VariableNotFound(format!("{ptr_expr:?}")))?; |
1400 | | - |
1401 | | - let ptr_ty = ptr_var.dwarf_type.as_ref().ok_or_else(|| { |
1402 | | - CodeGenError::DwarfError("Expression has no DWARF type information".to_string()) |
1403 | | - })?; |
1404 | | - |
1405 | | - // Unwrap typedef/qualified wrappers |
1406 | | - let mut ty = ptr_ty; |
1407 | | - loop { |
1408 | | - match ty { |
1409 | | - TypeInfo::TypedefType { |
1410 | | - underlying_type, .. |
1411 | | - } => ty = underlying_type.as_ref(), |
1412 | | - TypeInfo::QualifiedType { |
1413 | | - underlying_type, .. |
1414 | | - } => ty = underlying_type.as_ref(), |
1415 | | - _ => break, |
1416 | | - } |
1417 | | - } |
1418 | | - |
1419 | | - // Extract pointed-to (element) type and element size |
1420 | | - let (elem_ty, elem_size) = match ty { |
1421 | | - TypeInfo::PointerType { target_type, .. } => { |
1422 | | - let et = target_type.as_ref().clone(); |
1423 | | - let es = et.size(); |
1424 | | - let es = if es == 0 { 1 } else { es }; |
1425 | | - (et, es) |
1426 | | - } |
1427 | | - TypeInfo::ArrayType { element_type, .. } => { |
1428 | | - let et = element_type.as_ref().clone(); |
1429 | | - let es = et.size(); |
1430 | | - let es = if es == 0 { 1 } else { es }; |
1431 | | - (et, es) |
1432 | | - } |
1433 | | - TypeInfo::FunctionType { .. } => { |
1434 | | - return Err(CodeGenError::TypeError( |
1435 | | - "Pointer arithmetic is not supported on function pointers".to_string(), |
1436 | | - )) |
1437 | | - } |
1438 | | - _ => { |
1439 | | - return Err(CodeGenError::TypeError( |
1440 | | - "Pointer arithmetic requires a pointer or array expression".to_string(), |
1441 | | - )) |
1442 | | - } |
1443 | | - }; |
1444 | | - |
1445 | | - let base_location = dereference_location(&ptr_var.location) |
1446 | | - .map_err(|err| CodeGenError::DwarfError(err.to_string()))?; |
1447 | | - let byte_offset = index.saturating_mul(elem_size as i64); |
1448 | | - let location = add_location_offset(base_location, byte_offset) |
1449 | | - .map_err(|err| CodeGenError::DwarfError(err.to_string()))?; |
1450 | | - |
1451 | | - Ok((location, elem_ty)) |
1452 | | - } |
1453 | 1384 | } |
1454 | 1385 |
|
1455 | 1386 | #[cfg(test)] |
@@ -1673,21 +1604,14 @@ mod tests { |
1673 | 1604 | "ptr", |
1674 | 1605 | "int*", |
1675 | 1606 | Some(ptr_ty), |
1676 | | - location.clone(), |
| 1607 | + location, |
1677 | 1608 | Availability::Available, |
1678 | 1609 | ); |
1679 | 1610 |
|
1680 | 1611 | let value = ctx |
1681 | 1612 | .variable_read_plan_to_llvm_value(&plan, 0, None) |
1682 | 1613 | .expect("absolute address value should lower"); |
1683 | 1614 | assert!(matches!(value, BasicValueEnum::IntValue(_))); |
1684 | | - |
1685 | | - let pointee = dereference_location(&location) |
1686 | | - .expect("absolute address value should dereference to memory"); |
1687 | | - assert_eq!( |
1688 | | - pointee, |
1689 | | - VariableLocation::Address(AddressExpr::constant(0x2000)) |
1690 | | - ); |
1691 | 1615 | } |
1692 | 1616 |
|
1693 | 1617 | #[test] |
|
0 commit comments