3

Using the vxWorks API symFind() we can get the address of a global variable knowing its name. Is there a way to know the corresponding size of a symbol?

The fact is that the searched symbol could be of any type and I need to find it at runtime. So I basically can't use the sizeof directive.

Prof. Falken
  • 22,327
  • 18
  • 94
  • 163
greydet
  • 5,259
  • 3
  • 27
  • 49
  • Phew. I had to track this down using Google's cached copy of symLib.h. If you're using the C API, wouldn't it just be `sizeof` the returned variable or a dereference of it? – MrGomez Mar 22 '12 at 14:17
  • @MrGomez The fact is that the searched symbol could be of any type and I need to find it at runtime. So I basically can't use the sizeof directive. – greydet Mar 22 '12 at 15:44
  • @greydet: if you don't know the _type_ of the symbol, it cannot be used. Period. Ergo, I think you can know the type, ergo, you can use `sizeof` If those assumptions are wrong, you can't usefully use that function anyway. – Mooing Duck Mar 27 '12 at 17:50

1 Answers1

2

This is a priori impossible, since when you add a symbol, you never specify its size: the symAdd function just takes a SYMTAB_ID, a name, an address, a type ID, and a group ID. Some of the predefined type IDs imply a size (or at least, imply enough information that you could examine the data at the address and infer a size), but other predefined type IDs do not; and even if they all did, the API still wouldn't have any way to know about user-defined types (since it just sees them as opaque integer identifiers).

ruakh
  • 156,364
  • 23
  • 244
  • 282
  • That's right no information on symbol length is available from symbol table... I will use the output of a nm command on my object file to retrieve the length of symbols. That's not really straightforward but at less it does the job! – greydet Mar 27 '12 at 18:17