[RFC/RFA] new gdbarch method: NAME_OF_MALLOC

Andrew Cagney ac131313@ges.redhat.com
Thu Sep 12 17:15:00 GMT 2002


>> Can ``const char *'' be used?  I think you'll just need to tweak the 
>> function signature for find_function_in_inferior().  If you need to 
>> tweak more, yell! :-)
> 
> 
> Yes, actually, you were right. I thought that the compiler would yell to
> see one of the struct fields be a "const", but it did not.
> 
> I sent a patch that constains the tweaks separately, see
> http://sources.redhat.com/ml/gdb-patches/2002-09/msg00221.html.
> 
> This patch depends on the patch mentionned above.
> 
> 2002-09-12  Joel Brobecker  <brobecker@gnat.com>
> 
>         * gdbarch.sh (NAME_OF_MALLOC): New variable in the architecture
>         vector. Will be useful for Interix.
>         * gdbarch.h, gdbarch.c: Regenerate.
> 
>         * valops.c (value_allocate_space_in_inferior): Replace hard-coded
>         name of the malloc function by NAME_OF_MALLOC.

This is ok.

Andrew


>> doc/gdbint.texinfo will need a separate patch.
> 
> 
> Ah yes, right. I will work on that as soon as the code is approved.
> 
> Thanks,
> -- Joel
> 
> 
> 
> Index: gdbarch.sh
> ===================================================================
> RCS file: /cvs/src/src/gdb/gdbarch.sh,v
> retrieving revision 1.159
> diff -c -3 -p -r1.159 gdbarch.sh
> *** gdbarch.sh	6 Sep 2002 20:17:40 -0000	1.159
> --- gdbarch.sh	12 Sep 2002 23:55:42 -0000
> *************** m::CONSTRUCT_INFERIOR_ARGUMENTS:char *:c
> *** 660,665 ****
> --- 660,666 ----
>   F:2:DWARF2_BUILD_FRAME_INFO:void:dwarf2_build_frame_info:struct objfile *objfile:objfile:::0
>   f:2:ELF_MAKE_MSYMBOL_SPECIAL:void:elf_make_msymbol_special:asymbol *sym, struct minimal_symbol *msym:sym, msym:::default_elf_make_msymbol_special::0
>   f:2:COFF_MAKE_MSYMBOL_SPECIAL:void:coff_make_msymbol_special:int val, struct minimal_symbol *msym:val, msym:::default_coff_make_msymbol_special::0
> + v::NAME_OF_MALLOC:const char *:name_of_malloc::::"malloc":"malloc"::0
>   EOF
>   }
>   
> Index: valops.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/valops.c,v
> retrieving revision 1.69
> diff -c -3 -p -r1.69 valops.c
> *** valops.c	21 Aug 2002 17:24:31 -0000	1.69
> --- valops.c	12 Sep 2002 23:55:45 -0000
> *************** struct value *
> *** 138,144 ****
>   value_allocate_space_in_inferior (int len)
>   {
>     struct value *blocklen;
> !   struct value *val = find_function_in_inferior ("malloc");
>   
>     blocklen = value_from_longest (builtin_type_int, (LONGEST) len);
>     val = call_function_by_hand (val, 1, &blocklen);
> --- 138,144 ----
>   value_allocate_space_in_inferior (int len)
>   {
>     struct value *blocklen;
> !   struct value *val = find_function_in_inferior (NAME_OF_MALLOC);
>   
>     blocklen = value_from_longest (builtin_type_int, (LONGEST) len);
>     val = call_function_by_hand (val, 1, &blocklen);
> Index: gdbarch.h
> ===================================================================
> RCS file: /cvs/src/src/gdb/gdbarch.h,v
> retrieving revision 1.115
> diff -c -3 -p -r1.115 gdbarch.h
> *** gdbarch.h	6 Sep 2002 20:17:40 -0000	1.115
> --- gdbarch.h	12 Sep 2002 23:55:47 -0000
> *************** extern void set_gdbarch_addr_bits_remove
> *** 2207,2213 ****
>   #endif
>   #endif
>   
> ! /* It is not at all clear why SMASH_TEXT_ADDRESS is not folded into 
>      ADDR_BITS_REMOVE. */
>   
>   /* Default (function) for non- multi-arch platforms. */
> --- 2207,2213 ----
>   #endif
>   #endif
>   
> ! /* It is not at all clear why SMASH_TEXT_ADDRESS is not folded into
>      ADDR_BITS_REMOVE. */
>   
>   /* Default (function) for non- multi-arch platforms. */
> *************** extern void set_gdbarch_coff_make_msymbo
> *** 2529,2534 ****
> --- 2529,2550 ----
>   #if GDB_MULTI_ARCH
>   #if (GDB_MULTI_ARCH > GDB_MULTI_ARCH_PARTIAL) || !defined (COFF_MAKE_MSYMBOL_SPECIAL)
>   #define COFF_MAKE_MSYMBOL_SPECIAL(val, msym) (gdbarch_coff_make_msymbol_special (current_gdbarch, val, msym))
> + #endif
> + #endif
> + 
> + /* Default (value) for non- multi-arch platforms. */
> + #if (!GDB_MULTI_ARCH) && !defined (NAME_OF_MALLOC)
> + #define NAME_OF_MALLOC ("malloc")
> + #endif
> + 
> + extern const char * gdbarch_name_of_malloc (struct gdbarch *gdbarch);
> + extern void set_gdbarch_name_of_malloc (struct gdbarch *gdbarch, const char * name_of_malloc);
> + #if (GDB_MULTI_ARCH > GDB_MULTI_ARCH_PARTIAL) && defined (NAME_OF_MALLOC)
> + #error "Non multi-arch definition of NAME_OF_MALLOC"
> + #endif
> + #if GDB_MULTI_ARCH
> + #if (GDB_MULTI_ARCH > GDB_MULTI_ARCH_PARTIAL) || !defined (NAME_OF_MALLOC)
> + #define NAME_OF_MALLOC (gdbarch_name_of_malloc (current_gdbarch))
>   #endif
>   #endif
>   
> Index: gdbarch.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/gdbarch.c,v
> retrieving revision 1.147
> diff -c -3 -p -r1.147 gdbarch.c
> *** gdbarch.c	6 Sep 2002 20:17:40 -0000	1.147
> --- gdbarch.c	12 Sep 2002 23:55:51 -0000
> *************** struct gdbarch
> *** 267,272 ****
> --- 267,273 ----
>     gdbarch_dwarf2_build_frame_info_ftype *dwarf2_build_frame_info;
>     gdbarch_elf_make_msymbol_special_ftype *elf_make_msymbol_special;
>     gdbarch_coff_make_msymbol_special_ftype *coff_make_msymbol_special;
> +   const char * name_of_malloc;
>   };
>   
>   
> *************** struct gdbarch startup_gdbarch =
> *** 423,428 ****
> --- 424,430 ----
>     0,
>     0,
>     0,
> +   "malloc",
>     /* startup_gdbarch() */
>   };
>   
> *************** gdbarch_alloc (const struct gdbarch_info
> *** 553,558 ****
> --- 555,561 ----
>     current_gdbarch->construct_inferior_arguments = construct_inferior_arguments;
>     current_gdbarch->elf_make_msymbol_special = default_elf_make_msymbol_special;
>     current_gdbarch->coff_make_msymbol_special = default_coff_make_msymbol_special;
> +   current_gdbarch->name_of_malloc = "malloc";
>     /* gdbarch_alloc() */
>   
>     return current_gdbarch;
> *************** verify_gdbarch (struct gdbarch *gdbarch)
> *** 797,802 ****
> --- 800,806 ----
>     /* Skip verify of dwarf2_build_frame_info, has predicate */
>     /* Skip verify of elf_make_msymbol_special, invalid_p == 0 */
>     /* Skip verify of coff_make_msymbol_special, invalid_p == 0 */
> +   /* Skip verify of name_of_malloc, invalid_p == 0 */
>     buf = ui_file_xstrdup (log, &dummy);
>     make_cleanup (xfree, buf);
>     if (strlen (buf) > 0)
> *************** gdbarch_dump (struct gdbarch *gdbarch, s
> *** 1485,1490 ****
> --- 1489,1502 ----
>                           (long) current_gdbarch->memory_remove_breakpoint
>                           /*MEMORY_REMOVE_BREAKPOINT ()*/);
>   #endif
> + #ifdef NAME_OF_MALLOC
> +   fprintf_unfiltered (file,
> +                       "gdbarch_dump: NAME_OF_MALLOC # %s\n",
> +                       XSTRING (NAME_OF_MALLOC));
> +   fprintf_unfiltered (file,
> +                       "gdbarch_dump: NAME_OF_MALLOC = %ld\n",
> +                       (long) NAME_OF_MALLOC);
> + #endif
>   #ifdef NPC_REGNUM
>     fprintf_unfiltered (file,
>                         "gdbarch_dump: NPC_REGNUM # %s\n",
> *************** set_gdbarch_coff_make_msymbol_special (s
> *** 4953,4958 ****
> --- 4965,4987 ----
>                                          gdbarch_coff_make_msymbol_special_ftype coff_make_msymbol_special)
>   {
>     gdbarch->coff_make_msymbol_special = coff_make_msymbol_special;
> + }
> + 
> + const char *
> + gdbarch_name_of_malloc (struct gdbarch *gdbarch)
> + {
> +   gdb_assert (gdbarch != NULL);
> +   /* Skip verify of name_of_malloc, invalid_p == 0 */
> +   if (gdbarch_debug >= 2)
> +     fprintf_unfiltered (gdb_stdlog, "gdbarch_name_of_malloc called\n");
> +   return gdbarch->name_of_malloc;
> + }
> + 
> + void
> + set_gdbarch_name_of_malloc (struct gdbarch *gdbarch,
> +                             const char * name_of_malloc)
> + {
> +   gdbarch->name_of_malloc = name_of_malloc;
>   }
>   
>   




More information about the Gdb-patches mailing list