GDB 不列出 GHS 编译的 ELF 中的成员函数或命名空间函数

GDB doesn't list member functions or namespace functions in GHS compiled ELF

我正在尝试使用 GDB 调试由 Green Hills GHS 编译器从 C++ 源代码编译的 PowerPC ELF 映像。 GHS MULTI 调试器使用专有调试格式,但编译器也提供 -dwarf2 选项来生成本机 DWARF-2 调试信息。 GDB至少可以从DWARF-2中读取一些信息,并且可以做一些事情,比如将行号映射到地址和找到符号的地址,但是很多事情比如在成员函数中打印局部变量是行不通的。

我用针对 x86 的 g++ 和针对 PowerPC 的 GHS 编译了这个非常简单的程序来比较两者。 -dwarf2 和 -G 标志在顶层 .gpj 中设置,以便 GHS 生成 DWARF-2 调试信息。我做了一个 readelf --debug-dump 并确认 GHS 确实生成了看起来合理正确的 DWARF-2。

class ClassA {
public:
  int Method(bool arg) {
    int local_1 = arg * 2;
    member_var_ = local_1;
    return local_1;
  }
  int member_var_;
};

int FuncA(int arg) {
  int local_2 = arg * 2;
  return local_2;
}

double global_a = 1;

namespace NamespaceA {
  int FuncB(int arg) {
    int local_3 = arg * 2;
    return local_3;
  }
}

int main(int argc, char *argv[]) {  
  ClassA a;
  return a.Method(true);
}

GDB 能够列出 g++ 编译的 ELF 中的所有函数:

gdb hello
...
Reading symbols from hello...done.
(gdb) info func
All defined functions:

File hello.cc:
int ClassA::Method(bool);
int FuncA(int);
int NamespaceA::FuncB(int);
int main(int, char**);

GDB 不列出成员函数或在 GHS 编译的 ELF 的命名空间内声明的函数:

gdb hello
...
Reading symbols from hello...done.
(gdb) info func
All defined functions:

File src/hello.cc:
int FuncA(int);
int main(int, char**);

Non-debugging symbols:
...

GHS 生成的 DWARF-2 和 GDB 之间是否不兼容?

要支持命名空间,您至少需要 DWARF3 格式。看起来 DWARF2 无法表示 C++ 命名空间,因为它甚至在考虑 C++ 命名空间之前就已完成,请参阅 DWARF3 features:

3 Major New Features

3.1 C++ , including Namespaces

DWARF2 was completed before the C++ Standard and before C++ namespaces were even considered. DWARF3 provides a complete set of features using DW TAG namespace, DW TAG imported declaration, DW AT import, and DW AT extension that enables an implementation to represent the visible namespaces correctly in every function. Implementations may choose to emit a single namespace declaration showing the complete namespace at the end of the compilation unit as this is simpler, though it loses some of the details of some uses of C++ Namespaces.