Skip to content

无法解析C++继承成员的问题 #5

Description

@jiezhuo

非常感谢你对 “二级指针数据无法解析” 问题的详细解析,我仔细回顾了一下我遇到的问题,发现我的问题和他不是同一个问题,现整理如下:

现象

Image

test_elf-改后缀7z解压

我在使用 HSS_DataVisualizer 解析本仓库 Firmware 输出的 ELF 文件时,无法找到/添加:
但同一个 ELF 文件,在 JScope 中可以找到:

motor_thermistors[1].<Inherited>.temperature_

我目前的解决方法是用JScope解析elf,拿到那个变量的名称和地址,然后在HSS里面随便添加一个变量,再手动改为JScope获得的信息,并且后续在HSS中是可以手动更新的

相关源码

motor_thermistors 是全局数组对象,不是指针。

// Firmware/Board/v3/board.cpp
OffboardThermistorCurrentLimiter motor_thermistors[AXIS_COUNT];

motor_thermistors[1] 的类型是:

OffboardThermistorCurrentLimiter

OffboardThermistorCurrentLimiter 继承自 ThermistorCurrentLimiter

// Firmware/MotorControl/thermistor.hpp
class OffboardThermistorCurrentLimiter
    : public ThermistorCurrentLimiter,
      public ODriveIntf::OffboardThermistorCurrentLimiterIntf {
public:
    ...
};

temperature_ 定义在基类 ThermistorCurrentLimiter 中:

// Firmware/MotorControl/thermistor.hpp
class ThermistorCurrentLimiter
    : public CurrentLimiter,
      public ODriveIntf::ThermistorCurrentLimiterIntf {
public:
    ...
    float temperature_ = NAN; // [°C] NaN while the ODrive is initializing.
    ...
};

所以 temperature_ 是继承来的成员,不是 OffboardThermistorCurrentLimiter 直接声明的成员。

我的理解

JScope 中显示的<Inherited>:应该是调试器为了表示“基类/继承成员”而生成的虚拟节点。
它不是源码中的真实字段名,这个问题的核心像是 HSS_DataVisualizer 没有展开 C++ 基类成员。

也就是说,工具可能只解析了当前类型直接声明的成员:DW_TAG_member
但没有继续处理基类继承信息:DW_TAG_inheritance

期望行为

希望 HSS_DataVisualizer 可以支持解析 C++ 继承成员

// 例如可以识别
motor_thermistors[1].temperature_
// 或者像 JScope 一样展开
motor_thermistors[1].<Inherited>.temperature_

总结

该问题不是“指针目标地址运行时才能确定”的问题。
它更像是“C++ 继承成员没有被 ELF/DWARF 解析器展开”的问题。
JScope 能显示 motor_thermistors[1].<Inherited>.temperature_,说明 ELF/DWARF 里大概率包含足够的信息。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions