This is the mail archive of the gdb-prs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug symtab/11035] New: gdb ignores explicit scoping for ambiguous symbols


Take the trivial example using 2 shared objects:

----m.cpp----
#include <stdio.h>
#include <dlfcn.h>

typedef void (*vvf)();
vvf so1_func;
vvf so2_func;

void m()
{
  printf(">>>m\n");
  so1_func();
  so2_func();
  printf("<<<m\n");
}

int main(int argc, char *argv[])
{
  void *p = dlopen("./so1.so", RTLD_LOCAL|RTLD_LAZY);
  so1_func = (vvf)dlsym(p, "so1_func");
  printf("p=%p f=%p\n", p, so1_func);

  p = dlopen("./so2.so", RTLD_LOCAL|RTLD_LAZY);
  so2_func = (vvf)dlsym(p, "so2_func");
  printf("p=%p f=%p\n", p, so2_func);

  m();
}

----so1.cpp----
#include <stdio.h>

class A {
public:
  void pA() { printf("so1::pA() in %p\n", this); }
  int so1_a;
} foo;

extern "C" void so1_func()
{
  printf("so1::foo = %p\n", &foo);
  foo.pA();
}

----so2.cpp----
#include <stdio.h>

class A {
public:
  void pA() { printf("so2::pA() in %p\n", this); }
  int so2_a;
} foo;

extern "C" void so2_func()
{
  printf("so2::foo = %p\n", &foo);
  foo.pA();
}

----Makefile----
all: m so1.so so2.so

m: m.cpp
	$(CXX) -g m.cpp -o m -ldl

so1.so: so1.cpp
	$(CXX) -g so1.cpp -o so1.so -shared -rdynamic -fPIC

so2.so: so2.cpp
	$(CXX) -g so2.cpp -o so2.so -shared -rdynamic -fPIC

----

Executing ./m shows that both .so instances can quite happily maintain their own
"foo" instances with no confusion. However, breakpointing in gdb just before the
call to m():

26	  m();
(gdb) print foo
$1 = {so1_a = 0}
(gdb) print 'so1.cpp'::foo
$2 = {so1_a = 0}
(gdb) print 'so2.cpp'::foo
$3 = {so1_a = 0}
(gdb) print *(A*)0x7ffff7dbda38
$4 = {so1_a = 0}
(gdb) print *('so2.cpp'::A*)0x7ffff7dbda38
A syntax error in expression, near `)0x7ffff7dbda38'.
(gdb)

The scoping should direct gdb to a particular instance, however it is ignored so
there seems to be no way to directly inspect the other instance.

Even if you can extract the address of the instance (here, from the output of
m(), but usually via a conveniant variable or function argument), gdb will by
default interpret the cast in the context of the wrong module, and there doesn't
appear to tell it to use the definition of A from so2 instead.

-- 
           Summary: gdb ignores explicit scoping for ambiguous symbols
           Product: gdb
           Version: 6.8
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: symtab
        AssignedTo: unassigned at sourceware dot org
        ReportedBy: jsrhbz at kanargh dot force9 dot co dot uk
                CC: gdb-prs at sourceware dot org
  GCC host triplet: x86_64-redhat-linux-gnu


http://sourceware.org/bugzilla/show_bug.cgi?id=11035

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]