* how to search for a global type?
@ 2007-12-31 4:28 Gary Funck
2008-01-02 3:18 ` Daniel Jacobowitz
0 siblings, 1 reply; 6+ messages in thread
From: Gary Funck @ 2007-12-31 4:28 UTC (permalink / raw)
To: GDB List
To support UPC debugging, we need to be able to look up
runtime information. Case in point, we need to query
the structure of the target's shared pointer representation.
At preent, we're implmenting this query with the following
code (within gdb):
static
int
lookup_type_by_name (const char *type_name)
{
const struct symbol *sym;
const struct type *type;
int type_id;
sym = lookup_symbol_global (type_name, NULL, TYPES_DOMAIN, NULL);
if (!sym)
sym = lookup_symbol_global (type_name, NULL, STRUCT_DOMAIN, NULL);
if (!sym)
return 0;
type_id = get_type_id (SYMBOL_TYPE (sym));
return type_id;
}
This code doesn't find the type in question, in spite of the
fact that GDB has no problem finding the type from the
command line. For example,
(gdb) ptype upc_shared_ptr_t
type = struct shared_ptr_struct {
long unsigned int phase : 48;
short unsigned int thread : 16;
void *vaddr;
}
and
(gdb) info type upc_shared_ptr_t
All types matching regular expression "upc_shared_ptr_t":
File /upc/gcc-upc-4/src/libupc/smp/upc_access.c:
typedef shared_ptr_struct upc_shared_ptr_t;
File /upc/gcc-upc-4/src/libupc/smp/upc_barrier.c:
typedef shared_ptr_struct upc_shared_ptr_t;
[...]
I've added some simple debugging output to
lookup_symbol_global, to confirm that it is being
called with the expected parameters:
lookup_symbol_global(upc_shared_ptr_t, NULL, 6, NULL) called.
lookup_symbol_global(upc_shared_ptr_t, NULL, 2, NULL) called.
In both cases, the type can't be found.
What's the recommended way to perform this type lookup?
Thanks,
- Gary
configuration: x86_64, FC5, dwarf2 debugging info.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: how to search for a global type?
2007-12-31 4:28 how to search for a global type? Gary Funck
@ 2008-01-02 3:18 ` Daniel Jacobowitz
2008-01-02 5:16 ` Gary Funck
0 siblings, 1 reply; 6+ messages in thread
From: Daniel Jacobowitz @ 2008-01-02 3:18 UTC (permalink / raw)
To: Gary Funck; +Cc: GDB List
On Sun, Dec 30, 2007 at 08:28:44PM -0800, Gary Funck wrote:
> static
> int
> lookup_type_by_name (const char *type_name)
> {
> const struct symbol *sym;
> const struct type *type;
> int type_id;
> sym = lookup_symbol_global (type_name, NULL, TYPES_DOMAIN, NULL);
Are types global, or do they usually end up in the file's static
block? I'd guess the latter. Check maint print symbols.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: how to search for a global type?
2008-01-02 3:18 ` Daniel Jacobowitz
@ 2008-01-02 5:16 ` Gary Funck
2008-01-02 13:12 ` Daniel Jacobowitz
0 siblings, 1 reply; 6+ messages in thread
From: Gary Funck @ 2008-01-02 5:16 UTC (permalink / raw)
To: GDB List
On 01/01/08 22:17:50, Daniel Jacobowitz wrote:
> On Sun, Dec 30, 2007 at 08:28:44PM -0800, Gary Funck wrote:
>
> Are types global, or do they usually end up in the file's static
> block? I'd guess the latter. Check maint print symbols.
Not sure (excerpt from maint print symbols follows). The typedef
is defined in the runtime, not in the main source file. Thus,
if I run up until "main" and try "maint print symbols", I don't
see the typedef at all. If I position to one of the runtime
source files, then the typedef appears in the maint print
symbols output as below:
Symtab for file /upc/gcc-upc-4/src/libupc/smp/upc_access.c
Read from object file /upc/gdb-upc/wrk/a.out (0x954630)
Language: c++
[...]
block #000, object at 0xb40a30, 9 syms/buckets in 0x4015d8..0x4022bf, compiled with gcc2
float __getsf2(upc_shared_ptr_t); block object 0xb363c0, 0x4017ff..0x401836
void __putblk3(upc_shared_ptr_t, void *, size_t); block object 0xb3b0a0, 0x401b40..0x401b75
[...]
int THREADS; unresolved
long unsigned int __upc_page1_ref; unresolved
void *__upc_page1_base; unresolved
block #001, object at 0xb40990 under 0xb40a30, 6 syms/buckets in 0x4015d8..0x4022bf, compiled with gcc2
typedef long unsigned int size_t;
typedef signed char signed char;
typedef long int long int;
[...]
typedef short unsigned int short unsigned int;
typedef struct shared_ptr_struct {
long unsigned int phase : 48;
short unsigned int thread : 16;
void *vaddr;
} upc_shared_ptr_t;
^^^^^^^^^^^^^^^^^ typedef we're looking for
The typedef appears to be in inner block. Does that make it static?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: how to search for a global type?
2008-01-02 5:16 ` Gary Funck
@ 2008-01-02 13:12 ` Daniel Jacobowitz
2008-01-02 17:46 ` Gary Funck
0 siblings, 1 reply; 6+ messages in thread
From: Daniel Jacobowitz @ 2008-01-02 13:12 UTC (permalink / raw)
To: Gary Funck; +Cc: GDB List
On Tue, Jan 01, 2008 at 09:16:26PM -0800, Gary Funck wrote:
> The typedef appears to be in inner block. Does that make it static?
Block 0 is the global symbols; block 1 is the file static symbols.
Later blocks are the bodies of functions, et cetera.
It makes sense for types to be static if you think about it from the
right perspective, since types do not (generally) have linker
visibility; the linker can't patch up your code to reference a type
declared in another file.
In short, try just lookup_symbol?
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: how to search for a global type?
2008-01-02 13:12 ` Daniel Jacobowitz
@ 2008-01-02 17:46 ` Gary Funck
2008-01-02 18:02 ` Daniel Jacobowitz
0 siblings, 1 reply; 6+ messages in thread
From: Gary Funck @ 2008-01-02 17:46 UTC (permalink / raw)
To: GDB List; +Cc: Daniel Jacobowitz
On 01/02/08 08:06:30, Daniel Jacobowitz wrote:
> On Tue, Jan 01, 2008 at 09:16:26PM -0800, Gary Funck wrote:
> > The typedef appears to be in inner block. Does that make it static?
>
> Block 0 is the global symbols; block 1 is the file static symbols.
> Later blocks are the bodies of functions, et cetera.
>
> It makes sense for types to be static if you think about it from the
> right perspective, since types do not (generally) have linker
> visibility; the linker can't patch up your code to reference a type
> declared in another file.
>
> In short, try just lookup_symbol?
I did try lookup_symbol() as well, no go.
I'm currently using this approach:
static
int
lookup_type_by_name (const char *type_name)
{
const struct symbol *sym;
const struct type *type;
int type_id;
struct symbol_search *matches;
/* FIXME: add ^$ anchors to front/back of type_name, so
that the regex matches only the desired type name. */
search_symbols ((char *)type_name, TYPES_DOMAIN,
0 /* nfiles */, NULL /* files */, &matches);
if (!matches)
return 0;
/* Arbitrarily use the first match. */
sym = matches->symbol;
free_search_symbols (matches);
type_id = get_type_id (SYMBOL_TYPE (sym));
return type_id;
}
Search_symbols() finds the type definition that we're interested in.
I think one difficulty is that the current file doesn't
define the type. It is defined in the runtime files.
I haven't tried following the logic, but could you briefly
explain the raltionship between block vectors and symbol
tables?
thanks,
- Gary
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: how to search for a global type?
2008-01-02 17:46 ` Gary Funck
@ 2008-01-02 18:02 ` Daniel Jacobowitz
0 siblings, 0 replies; 6+ messages in thread
From: Daniel Jacobowitz @ 2008-01-02 18:02 UTC (permalink / raw)
To: Gary Funck; +Cc: GDB List
On Wed, Jan 02, 2008 at 09:41:58AM -0800, Gary Funck wrote:
> I did try lookup_symbol() as well, no go.
You may need to trace how ptype finds it, then. I would expect
lookup_symbol to work. If there is no symbol in the global blocks, it
falls back to static blocks (not just the current file's).
search_symbols is going to be much less efficient.
> I think one difficulty is that the current file doesn't
> define the type. It is defined in the runtime files.
>
> I haven't tried following the logic, but could you briefly
> explain the raltionship between block vectors and symbol
> tables?
Each file has a blockvector. Block 0 is its contribution to the
global symbol table. Block 1 is its static symbol table, including
things like types. Later blocks are children of one or the other,
representing functions (and further inner blocks of functions).
The symbol table is made up of the contents of those blocks, though
indexed differently (I think, I have not checked in a while).
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2008-01-02 18:02 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-31 4:28 how to search for a global type? Gary Funck
2008-01-02 3:18 ` Daniel Jacobowitz
2008-01-02 5:16 ` Gary Funck
2008-01-02 13:12 ` Daniel Jacobowitz
2008-01-02 17:46 ` Gary Funck
2008-01-02 18:02 ` Daniel Jacobowitz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox