public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug symtab/11035] New: gdb ignores explicit scoping for ambiguous symbols
@ 2009-11-30 16:16 jsrhbz at kanargh dot force9 dot co dot uk
  2010-03-22 15:13 ` [Bug symtab/11035] " tromey at redhat dot com
  0 siblings, 1 reply; 3+ messages in thread
From: jsrhbz at kanargh dot force9 dot co dot uk @ 2009-11-30 16:16 UTC (permalink / raw)
  To: gdb-prs

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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-12-27 13:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-11035-4717@http.sourceware.org/bugzilla/>
2023-12-27 13:12 ` [Bug symtab/11035] gdb ignores explicit scoping for ambiguous symbols ssbssa at sourceware dot org
2023-12-27 13:12 ` ssbssa at sourceware dot org
2009-11-30 16:16 [Bug symtab/11035] New: " jsrhbz at kanargh dot force9 dot co dot uk
2010-03-22 15:13 ` [Bug symtab/11035] " tromey at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).