makedumpfile: Introduce routines to get type name from debuginfo.
Subsystems (2)
PATCH v2 4/8 makedumpfile: Introduce routines to get type name from debuginfo.
From: Mahesh Salgaonkar <[email protected]>
This patch implements following routines that returns type, type name and size of kernel symbol/member using dwarf info:
char *get_symbol_type_name(); char *get_member_type_name(); long get_pointer_size();
These routines will be used to resolve symbol/member information specified through filter config commands.
---
makedumpfile.c | 142 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- makedumpfile.h | 13 +++++ 2 files changed, 148 insertions(+), 7 deletions(-)
makedumpfile.c +136 -6
@@ -30,6 +30,7 @@ struct module_sym_table mod_st = { 0 };char filename_stdout[] =FILENAME_STDOUT ;int message_level; +long pointer_size;/* * Forward declarations
@@ -1822,6 +1823,41 @@ check_array_type(Dwarf *dwarfd, Dwarf_Die *die)return TRUE; } +static int +get_dwarf_base_type (Dwarf *dwarfd,Dwarf_Die *die) +{ +int tag; +const char *name; + +while (get_die_type (dwarfd, die, die)) { + tag =dwarf_tag (die); +switch (tag) { +case DW_TAG_array_type: + dwarf_info.type_flag |=TYPE_ARRAY ; +break ; +case DW_TAG_pointer_type: + dwarf_info.type_flag |=TYPE_PTR ; +break ; +case DW_TAG_structure_type: + dwarf_info.type_flag |=TYPE_STRUCT ; +break ; +case DW_TAG_base_type: + dwarf_info.type_flag |=TYPE_BASE ; +break ; + } + } + + name =dwarf_diename (die); +if (name) + dwarf_info.type_name =strdup (name); +else if (dwarf_info.type_flag ==TYPE_PTR ) + dwarf_info.type_name =strdup ("void" ); + + dwarf_info.struct_size =dwarf_bytesize (die); + +return TRUE; +} +/* * Function for searching struct page.union.struct.mapping. */
@@ -1902,6 +1938,15 @@ search_member(Dwarf *dwarfd, Dwarf_Die *die)continue ;switch (dwarf_info.cmd) { +case DWARF_INFO_GET_MEMBER_TYPE : +if ((!name) ||strcmp (name, dwarf_info.member_name)) +continue ; +/* +* Get the member offset. +*/ +if (!get_dwarf_base_type (dwarfd, walker)) +continue ; +return ;case DWARF_INFO_GET_MEMBER_OFFSET :if ((!name) ||strcmp (name, dwarf_info.member_name))continue ;
@@ -1964,6 +2009,7 @@ is_search_structure(int cmd) {if ((cmd ==DWARF_INFO_GET_STRUCT_SIZE ) || (cmd ==DWARF_INFO_GET_MEMBER_OFFSET ) + || (cmd ==DWARF_INFO_GET_MEMBER_TYPE ) || (cmd ==DWARF_INFO_GET_MEMBER_OFFSET_IN_UNION ) || (cmd ==DWARF_INFO_GET_MEMBER_OFFSET_1ST_UNION ) || (cmd ==DWARF_INFO_GET_MEMBER_ARRAY_LENGTH ))
@@ -1985,6 +2031,7 @@ int is_search_symbol(int cmd) {if ((cmd ==DWARF_INFO_GET_SYMBOL_ARRAY_LENGTH ) + || (cmd ==DWARF_INFO_GET_SYMBOL_TYPE ) || (cmd ==DWARF_INFO_CHECK_SYMBOL_ARRAY_TYPE ))return TRUE;else
@@ -2041,6 +2088,7 @@ search_structure(Dwarf *dwarfd, Dwarf_Die *die, int *found)switch (dwarf_info.cmd) {case DWARF_INFO_GET_STRUCT_SIZE :break ; +case DWARF_INFO_GET_MEMBER_TYPE :case DWARF_INFO_GET_MEMBER_OFFSET :case DWARF_INFO_GET_MEMBER_OFFSET_IN_UNION :case DWARF_INFO_GET_MEMBER_OFFSET_1ST_UNION :
@@ -2173,6 +2221,9 @@ search_symbol(Dwarf *dwarfd, Dwarf_Die *die, int *found)case DWARF_INFO_CHECK_SYMBOL_ARRAY_TYPE :check_array_type (dwarfd, die);break ; +case DWARF_INFO_GET_SYMBOL_TYPE : +get_dwarf_base_type (dwarfd, die); +break ; } }
@@ -2249,6 +2300,10 @@ get_debug_info(void)*/ while (dwarf_nextcu (dwarfd, off, &next_off, &header_size, &abbrev_offset, &address_size, &offset_size) ==0 ) { +if (dwarf_info.cmd ==DWARF_INFO_GET_PTR_SIZE ) { + dwarf_info.struct_size = address_size; +break ; + } off += header_size;if (dwarf_offdie (dwarfd, off, &cu_die) ==NULL ) {ERRMSG ("Can't get CU die.\n" );
@@ -2287,6 +2342,47 @@ get_structure_size(char *structname, int flag_typedef) }/* +* Get the size of pointer. +*/ +long +get_pointer_size () +{ + dwarf_info.cmd =DWARF_INFO_GET_PTR_SIZE ; +/* reuse struct_size member to report pointer size */ + dwarf_info.struct_size =NOT_FOUND_STRUCTURE ; + +if (!get_debug_info ()) +return FAILED_DWARFINFO ; + +return dwarf_info.struct_size; +} + +/* +* Get the type of given symbol. +*/ +char * +get_symbol_type_name (char *symname,int cmd,long *size, +unsigned long *flag) +{ + dwarf_info.cmd = cmd; + dwarf_info.symbol_name = symname; + dwarf_info.type_name =NULL ; + dwarf_info.struct_size =NOT_FOUND_STRUCTURE ; + dwarf_info.type_flag =0 ; + +if (!get_debug_info ()) +return NULL ; + +if (size) + *size = dwarf_info.struct_size; + +if (flag) + *flag = dwarf_info.type_flag; + +return dwarf_info.type_name; +} + +/* * Get the offset of member. */ long
@@ -2305,6 +2401,35 @@ get_member_offset(char *structname, char *membername, int cmd) }/* +* Get the type name and size of member. +*/ +char * +get_member_type_name (char *structname,char *membername,int cmd,long *size, +unsigned long *flag) +{ + dwarf_info.cmd = cmd; + dwarf_info.struct_name = structname; + dwarf_info.struct_size =NOT_FOUND_STRUCTURE ; + dwarf_info.member_name = membername; + dwarf_info.type_name =NULL ; + dwarf_info.type_flag =0 ; + +if (!get_debug_info ()) +return NULL ; + +if (dwarf_info.struct_size ==NOT_FOUND_STRUCTURE ) +return NULL ; + +if (size) + *size = dwarf_info.struct_size; + +if (flag) + *flag = dwarf_info.type_flag; + +return dwarf_info.type_name; +} + +/* * Get the length of array. */ long
@@ -2402,6 +2527,8 @@ get_symbol_info(void)if (SYMBOL (node_memblk) !=NOT_FOUND_SYMBOL )SYMBOL_ARRAY_LENGTH_INIT (node_memblk,"node_memblk" ); + pointer_size =get_pointer_size (); +return TRUE; }
@@ -7519,13 +7646,16 @@ load_module_symbols(void)for (nsym =1 ; nsym < num_symtab; nsym++) {Elf32_Sym *sym32;Elf64_Sym *sym64; -/* -* We can not depend on info->flag_elf64_memory if -* the input vmcore file is kdump-compressed format. -* We will fix this in the next patch and remove the -* dependancy on info->flag_elf64_memory. +/* If case of ELF vmcore then the word size can be +* determined using info->flag_elf64_memory flag. +* But in case of kdump-compressed dump, kdump header +* does not carry word size info. May be in future +* this info will be available in kdump header. +* Until then, in order to make this logic work on both +* situation we depend on pointer_size that is +* extracted from vmlinux dwarf information. */ -if (info->flag_elf64_memory) { +if ((pointer_size *8 ) ==64 ) { sym64 = (Elf64_Sym *) (symtab_mem + (nsym *sizeof (Elf64_Sym))); sym_info[nsym].value =
makedumpfile.h +12 -1
@@ -1242,7 +1242,10 @@ enum {DWARF_INFO_GET_TYPEDEF_SIZE ,DWARF_INFO_GET_TYPEDEF_SRCNAME ,DWARF_INFO_GET_ENUM_NUMBER , -DWARF_INFO_CHECK_SYMBOL_ARRAY_TYPE +DWARF_INFO_CHECK_SYMBOL_ARRAY_TYPE , +DWARF_INFO_GET_SYMBOL_TYPE , +DWARF_INFO_GET_MEMBER_TYPE , + DWARF_INFO_GET_PTR_SIZE, }; struct dwarf_info {
@@ -1257,13 +1260,21 @@ struct dwarf_info {Elf *elfd;/* OUT */ Dwarf *dwarfd;/* OUT */ Dwfl *dwfl;/* OUT */ +char *type_name;/* OUT */ long struct_size;/* OUT */ long member_offset;/* OUT */ long array_length;/* OUT */ long enum_number;/* OUT */ +unsigned char type_flag;/* OUT */ char src_name[LEN_SRCFILE ];/* OUT */ }; +/* flags for dwarf_info.type_flag */ +#define TYPE_BASE 0x01 +#define TYPE_ARRAY 0x02 +#define TYPE_PTR 0x04 +#define TYPE_STRUCT 0x08 +extern struct dwarf_info dwarf_info;int readmem (int type_addr,unsigned long long addr,void *bufptr,size_t size);
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Hi Mahesh,
A pointer size can been gotton by sizeof(void *), and pointer (virtual address) can been defined as "unsigned long".
I think we can make this patch simple. How about the attached patch ?
Thanks
Ken'ichi Ohmichi
makedumpfile.c +14 -41
@@ -34,7 +34,6 @@ struct erase_info *erase_info = NULL;unsigned long num_erase_info =1 ;/* Node 0 is unused. */ char filename_stdout[] =FILENAME_STDOUT ; -long pointer_size;char config_buf[BUFSIZE_FGETS ];/*
@@ -2058,10 +2057,6 @@ get_debug_info(void)*/ while (dwarf_nextcu (dwarfd, off, &next_off, &header_size, &abbrev_offset, &address_size, &offset_size) ==0 ) { -if (dwarf_info.cmd ==DWARF_INFO_GET_PTR_SIZE ) { - dwarf_info.struct_size = address_size; -break ; - } off += header_size;if (dwarf_offdie (dwarfd, off, &cu_die) ==NULL ) {ERRMSG ("Can't get CU die.\n" );
@@ -2105,14 +2100,7 @@ get_structure_size(char *structname, int flag_typedef)long get_pointer_size () { - dwarf_info.cmd =DWARF_INFO_GET_PTR_SIZE ; -/* reuse struct_size member to report pointer size */ - dwarf_info.struct_size =NOT_FOUND_STRUCTURE ; - -if (!get_debug_info ()) -return FAILED_DWARFINFO ; - -return dwarf_info.struct_size; +return sizeof (void *); }/*
@@ -2285,8 +2273,6 @@ get_symbol_info(void)if (SYMBOL (node_memblk) !=NOT_FOUND_SYMBOL )SYMBOL_ARRAY_LENGTH_INIT (node_memblk,"node_memblk" ); - pointer_size =get_pointer_size (); -return TRUE; }
@@ -7782,7 +7768,7 @@ load_module_symbols(void)* situation we depend on pointer_size that is * extracted from vmlinux dwarf information. */ -if ((pointer_size *8 ) ==64 ) { +if ((get_pointer_size () *8 ) ==64 ) { sym64 = (Elf64_Sym *) (symtab_mem + (nsym *sizeof (Elf64_Sym))); sym_info[nsym].value =
@@ -7863,8 +7849,8 @@ print_config_entry(struct config_entry *ce)DEBUG_MSG ("Type Name: %s, " , ce->type_name);DEBUG_MSG ("flag: %x, " , ce->flag);DEBUG_MSG ("Type flag: %lx, " , ce->type_flag); -DEBUG_MSG ("sym_addr: %llx, " , ce->sym_addr); -DEBUG_MSG ("addr: %llx, " , ce->addr); +DEBUG_MSG ("sym_addr: %lx, " , ce->sym_addr); +DEBUG_MSG ("addr: %lx, " , ce->addr);DEBUG_MSG ("offset: %lx, " , ce->offset);DEBUG_MSG ("size: %zd\n" , ce->size);
@@ -8399,29 +8385,16 @@ err_out:return NULL ; } -static unsigned long long +static unsigned long read_pointer_value (unsigned long long addr) { -uint32_t val_32; -uint64_t val_64; +unsigned long val; -switch (pointer_size) { -case 4 : -if (!readmem (VADDR , addr, &val_32,sizeof (val_32))) { -ERRMSG ("Can't read pointer value\n" ); -return 0 ; - } -return (unsigned long long )val_32; -break ; -case 8 : -if (!readmem (VADDR , addr, &val_64,sizeof (val_64))) { -ERRMSG ("Can't read pointer value\n" ); -return 0 ; - } -return (unsigned long long )val_64; -break ; +if (!readmem (VADDR , addr, &val,sizeof (val))) { +ERRMSG ("Can't read pointer value\n" ); +return 0 ; } -return 0 ; +return val; }int
@@ -8621,7 +8594,7 @@ get_config_symbol_addr(struct config_entry *ce,unsigned long long base_addr, char *base_struct_name) { -unsigned long long addr =0 ; + unsigned long addr = 0;if (!(ce->flag &ENTRY_RESOLVED )) {if (!resolve_config_entry (ce, base_addr, base_struct_name))
@@ -8646,7 +8619,7 @@ get_config_symbol_addr(struct config_entry *ce,*/ while (ce->index < ce->array_length) { addr =read_pointer_value (ce->addr + - (ce->index * pointer_size)); + (ce->index *get_pointer_size ())); ce->index++;if (addr)break ;
@@ -8728,7 +8701,7 @@ get_config_symbol_size(struct config_entry *ce,else {if (ce->type_flag &TYPE_ARRAY ) {if (ce->type_flag &TYPE_PTR ) -return ce->array_length * pointer_size; +return ce->array_length *get_pointer_size ();else return ce->array_length * ce->size; }
@@ -8909,7 +8882,7 @@ update_filter_info(struct config_entry *filter_symbol,return FALSE;if (filter_symbol->nullify) - size = pointer_size; + size =get_pointer_size ();else if (size_symbol) { size =get_config_symbol_size (size_symbol,0 ,NULL );if (message_level &ML_PRINT_DEBUG_MSG )
makedumpfile.h +1 -2
@@ -1218,7 +1218,6 @@ enum {DWARF_INFO_CHECK_SYMBOL_ARRAY_TYPE ,DWARF_INFO_GET_SYMBOL_TYPE , DWARF_INFO_GET_MEMBER_TYPE, - DWARF_INFO_GET_PTR_SIZE, }; struct dwarf_info {
@@ -1284,7 +1283,7 @@ struct config_entry {unsigned short flag;unsigned short nullify;unsigned long long sym_addr;/* Symbol address */ -unsigned long long addr;/* Symbol address or +unsigned long addr;/* Symbol address or value pointed by sym_addr */ unsigned long long cmp_addr;/* for LIST_ENTRY */ unsigned long offset;
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Hi Ken'ichi,
Quoted 7 lines · Ken'ichi Ohmichi
Hi Mahesh,
A pointer size can been gotton by
sizeof(void *), and pointer (virtual address) can been defined as "unsigned long".
I think we can make this patch simple. How about the attached patch ?
Yup, the patch looks simpler and good.
Quoted 27 lines
Thanks
Ken'ichi Ohmichimakedumpfile.c +0
-5@@ -34,7 +34,6 @@ struct erase_info *erase_info = NULL;unsigned long num_erase_info =1 ;/* Node 0 is unused. */ char filename_stdout[] =FILENAME_STDOUT ; -long pointer_size;char config_buf[BUFSIZE_FGETS ];/* @@ -2058,10 +2057,6 @@ get_debug_info(void)*/ while (dwarf_nextcu (dwarfd, off, &next_off, &header_size, &abbrev_offset, &address_size, &offset_size) ==0 ) { -if (dwarf_info.cmd ==DWARF_INFO_GET_PTR_SIZE ) { - dwarf_info.struct_size = address_size; -break ; - } off += header_size;if (dwarf_offdie (dwarfd, off, &cu_die) ==NULL ) {ERRMSG ("Can't get CU die.\n" );
[...]
makedumpfile.c print_config_entry(struct config_entry *ce) · line 7852
Quoted 7 lines
makedumpfile.c +1
-2@@ -7863,8 +7849,8 @@ print_config_entry(struct config_entry *ce)DEBUG_MSG ("Type Name: %s, " , ce->type_name);DEBUG_MSG ("flag: %x, " , ce->flag);DEBUG_MSG ("Type flag: %lx, " , ce->type_flag); -DEBUG_MSG ("sym_addr: %llx, " , ce->sym_addr); -DEBUG_MSG ("addr: %llx, " , ce->addr); +DEBUG_MSG ("sym_addr: %lx, " , ce->sym_addr);
Above change throws compilation warning. The sym_addr is unsigned long long, %llx still holds good.
Quoted 4 lines
makedumpfile.c +1
-0+DEBUG_MSG ("addr: %lx, " , ce->addr);DEBUG_MSG ("offset: %lx, " , ce->offset);DEBUG_MSG ("size: %zd\n" , ce->size);
[...]
makedumpfile.c struct config_entry { · line 1289
Quoted 10 lines
makedumpfile.c +1
-1@@ -1284,7 +1283,7 @@ struct config_entry {unsigned short flag;unsigned short nullify;unsigned long long sym_addr;/* Symbol address */ -unsigned long long addr;/* Symbol address or +unsigned long addr;/* Symbol address or value pointed by sym_addr */ unsigned long long cmp_addr;/* for LIST_ENTRY */ unsigned long offset;
I tested this patch and works fine.
Thanks,
-Mahesh.
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Hi Mahesh,
Thank you for your review and test.
Quoted 42 lines · On Thu, 04 Aug 2011 12:13:22 +0530 Mahesh Jagannath Salgaonkar…
Quoted 7 lines · Ken'ichi Ohmichi
Hi Mahesh,
A pointer size can been gotton by
sizeof(void *), and pointer (virtual address) can been defined as "unsigned long".
I think we can make this patch simple. How about the attached patch ?Yup, the patch looks simpler and good.
Quoted 27 lines
Thanks
Ken'ichi Ohmichimakedumpfile.c +0
-5@@ -34,7 +34,6 @@ struct erase_info *erase_info = NULL;unsigned long num_erase_info =1 ;/* Node 0 is unused. */ char filename_stdout[] =FILENAME_STDOUT ; -long pointer_size;char config_buf[BUFSIZE_FGETS ];/* @@ -2058,10 +2057,6 @@ get_debug_info(void)*/ while (dwarf_nextcu (dwarfd, off, &next_off, &header_size, &abbrev_offset, &address_size, &offset_size) ==0 ) { -if (dwarf_info.cmd ==DWARF_INFO_GET_PTR_SIZE ) { - dwarf_info.struct_size = address_size; -break ; - } off += header_size;if (dwarf_offdie (dwarfd, off, &cu_die) ==NULL ) {ERRMSG ("Can't get CU die.\n" );[...]
Quoted 10 lines
makedumpfile.c print_config_entry(struct config_entry *ce) · line 7852
Quoted 7 lines
makedumpfile.c +1
-2@@ -7863,8 +7849,8 @@ print_config_entry(struct config_entry *ce)DEBUG_MSG ("Type Name: %s, " , ce->type_name);DEBUG_MSG ("flag: %x, " , ce->flag);DEBUG_MSG ("Type flag: %lx, " , ce->type_flag); -DEBUG_MSG ("sym_addr: %llx, " , ce->sym_addr); -DEBUG_MSG ("addr: %llx, " , ce->addr); +DEBUG_MSG ("sym_addr: %lx, " , ce->sym_addr);Above change throws compilation warning. The
sym_addris unsigned long long, %llx still holds good.
Nice catch, I fixed the above.
Quoted 7 lines
Quoted 4 lines
makedumpfile.c +1
-0+DEBUG_MSG ("addr: %lx, " , ce->addr);DEBUG_MSG ("offset: %lx, " , ce->offset);DEBUG_MSG ("size: %zd\n" , ce->size);[...]
Quoted 12 lines
makedumpfile.c struct config_entry { · line 1289
Quoted 10 lines
makedumpfile.c +1
-1@@ -1284,7 +1283,7 @@ struct config_entry {unsigned short flag;unsigned short nullify;unsigned long long sym_addr;/* Symbol address */ -unsigned long long addr;/* Symbol address or +unsigned long addr;/* Symbol address or value pointed by sym_addr */ unsigned long long cmp_addr;/* for LIST_ENTRY */ unsigned long offset;I tested this patch and works fine.
Thank you.
I have merged this patch.
Thanks
Ken'ichi Ohmichi
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec