Adam
Adam

Reputation: 389

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

I'm attempting to use GDB to debug a PowerPC ELF image compiled by the Green Hills GHS compiler from C++ source. The GHS MULTI debugger uses a proprietary debugging format, but the compiler provides a -dwarf2 option to produce native DWARF-2 debugging information as well. GDB is able to read at least some information from the DWARF-2, and can do things like map line numbers to addresses and find the addresses of symbols, but many things such printing local variables in member functions do not work.

I compiled this very simple program with g++ targeting x86 and GHS targeting PowerPC to compare the two. The -dwarf2 and -G flags were set in the top level .gpj for GHS to produce DWARF-2 debug information. I did a readelf --debug-dump and confirmed that GHS did generate what looks like reasonably correct 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 is able to list all the functions from the g++ compiled 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 does not list the member function or the function declared inside a namespace from the GHS compiled 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:
...

Is there an incompatibility between GHS generated DWARF-2 and GDB?

Upvotes: 0

Views: 990

Answers (1)

ks1322
ks1322

Reputation: 35716

For namespaces support you need at least DWARF3 format. It looks like DWARF2 is unable to represent C++ namespaces because it was completed before C++ namespaces were even considered, see 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.

Upvotes: 2

Related Questions