Hi,
is there any command to see symbol table info.
will it show where its allocating memory for varibales golbals & locals and code.(i mean the segments).
i read there is a section called read only data segment and this is where initialized data such as strings stores.
i have wriiten the following program and its giving segmentation for strings but not others.
any idea whats the proper reason.
char *p="test";
int g=10;
int main()
{
g=20;// no segmentation
printf("%d",g);
getchar();
*p='T';// generates segmentation
printf("%s",p);
return 0;
}
[User@telnet spark]$ objdump -t te.o
te.o: file format elf32-i386
SYMBOL TABLE:
00000000 l df *ABS* 00000000 te.c
00000000 l d .text 00000000
00000000 l d .data 00000000
00000000 l d .bss 00000000
00000000 l d .rodata 00000000
00000000 l d .comment 00000000
00000000 g O .data 00000004 p
00000000 g F .text 00000035 main
00000000 *UND* 00000000 printf
when i use objdump its giving the list of options that can be used with it.
i tried all but dint understand much.
i want the info in following format:
symbolname section address default val
g rwdata ---- 0
and so on
if any global variables are present it should give U ( undefined/ defined later)
MrUser, your code is problematic. Consider the following 2 statements:
char p[] = "test";
char *p = "test";
In the first statement, a mutable (modifiable or non-constant) string p is declared as an array of character and initialized with the string "test". The size of array p is 5 bytes including a null terminator. The result of *p = 'T' is defined and works as expected.
In the second statement an immutable (AKA constant) string litteral is declared and the base address of the memory where the compiler stores the string litteral is assigned to the pointer variable p. In this case, the result of *p = 'T' is undefined as you found out.
When you want a mutable string, i.e. a string which can be modified, use initialization instead of assignment.