This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] Fix ptype problem printing typedefs defined differently in different compilation units
On Monday 23 January 2006 11:12, Daniel Jacobowitz wrote:
> I don't understand. What doesn't work? Is it something that works
> without the patch, or not?
Doesn't work without the patch, as it uses the type for the first
symtab it happens to find that has a definition for that type.
> I don't understand how your examples relate
> to your description of the problem anymore.
OK, I've attached a typescript at the bottom of this mail showing how
it fails in the presence of a core and/or running executable.
> > So something like the following, which currently produces an error:
> >
> > (gdb) ptype 'main.c'::foo
> > Cannot look up value of a typedef
>
> Well that seems like a reasonable thing to fix anyway; ptype (and
> sizeof!) should be using a non-side-effects evaluation anyway.
I can look at this, though it may be a week or so.
-Fred
============================================================================
Here is a simple testcase
$ cat main.c
typedef long foo;
foo longfoo;
main ()
{
extern charfoo (char);
extern intfoo (int);
int a = 5;
a = intfoo (a);
a = charfoo (a);
printf ("a = %d (should be 20)\n", a);
*(char *)0 = 0;
}
$ cat int.c
typedef int foo;
intfoo (foo a)
{
return (2 * a);
}
$ cat char.c
typedef char foo;
charfoo (foo a)
{
return (2 * a);
}
============================================================================
Build testcase on Fedora Core 4 and generate corefile
$ make
gcc -g --save-temps -c -o main.o main.c
main.c: In function âmainâ:
main.c:12: warning: incompatible implicit declaration of built-in function âprintfâ
gcc -g --save-temps -c -o char.o char.c
gcc -g --save-temps -c -o int.o int.c
gcc -o main main.o char.o int.o
$ ./main
a = 20 (should be 20)
Segmentation fault (core dumped)
$ mv core.* core
============================================================================
Use gdb to examine just the executable file
$ ../gdb main
(gdb) list main
1 typedef long foo;
2 foo longfoo;
3
4 main ()
5 {
6 extern charfoo (char);
7 extern intfoo (int);
8 int a = 5;
9
10 a = intfoo (a);
(gdb) ptype foo
type = long int <===== OK
(gdb) list charfoo
1 typedef char foo;
2
3 charfoo (foo a)
4 {
5 return (2 * a);
6 }
(gdb) ptype foo
type = char <===== OK
(gdb) list intfoo
1 typedef int foo;
2
3 intfoo (foo a)
4 {
5 return (2 * a);
6 }
(gdb) ptype foo
type = int <===== OK
(gdb) quit
============================================================================
Use gdb to examine the executable file and core file
$ ../gdb main core
#0 0x080483de in main () at main.c:13
13 *(char *)0 = 0;
(gdb) list main
1 typedef long foo;
2 foo longfoo;
3
4 main ()
5 {
6 extern charfoo (char);
7 extern intfoo (int);
8 int a = 5;
9
10 a = intfoo (a);
(gdb) ptype foo
type = long int <===== OK
(gdb) list charfoo
1 typedef char foo;
2
3 charfoo (foo a)
4 {
5 return (2 * a);
6 }
(gdb) ptype foo
type = long int <===== Prints using frame context
(gdb) list intfoo
1 typedef int foo;
2
3 intfoo (foo a)
4 {
5 return (2 * a);
6 }
(gdb) ptype foo
type = long int <===== Prints using frame context
(gdb) quit
============================================================================