From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23282 invoked by alias); 4 Dec 2005 18:59:59 -0000 Received: (qmail 23274 invoked by uid 22791); 4 Dec 2005 18:59:58 -0000 X-Spam-Check-By: sourceware.org Received: from sibelius.xs4all.nl (HELO sibelius.xs4all.nl) (82.92.89.47) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sun, 04 Dec 2005 18:59:56 +0000 Received: from elgar.sibelius.xs4all.nl (root@elgar.sibelius.xs4all.nl [192.168.0.2]) by sibelius.xs4all.nl (8.13.4/8.13.4) with ESMTP id jB4IxrhB013139 for ; Sun, 4 Dec 2005 19:59:53 +0100 (CET) Received: from elgar.sibelius.xs4all.nl (kettenis@localhost.sibelius.xs4all.nl [127.0.0.1]) by elgar.sibelius.xs4all.nl (8.13.4/8.13.3) with ESMTP id jB4IxrDw019476 for ; Sun, 4 Dec 2005 19:59:53 +0100 (CET) Received: (from kettenis@localhost) by elgar.sibelius.xs4all.nl (8.13.4/8.13.4/Submit) id jB4IxrVO001319; Sun, 4 Dec 2005 19:59:53 +0100 (CET) Date: Sun, 04 Dec 2005 22:05:00 -0000 Message-Id: <200512041859.jB4IxrVO001319@elgar.sibelius.xs4all.nl> From: Mark Kettenis To: gdb-patches@sourceware.org Subject: [RFC/RFA] Deal with -g1 generated DWARF2 debug info Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2005-12/txt/msg00086.txt.bz2 In an attempt to improve backtraces in bug reports, we now build libraries with -g1 on OpenBSD. This revealed an interesting gdb issue. A few testsuite tests now FAILed with: No memory available to program: call to malloc failed That's pretty annoying, since it makes passing strings to C functions basicallt impossible. I noticed that where previously we had: (gdb) ptype malloc type = int () with -g1 we get: (gdb) ptype malloc type = void () As a result GDB thinks there is no return value from malloc and things the malloc call failed. The cause of the problem is that DWARF2 doesn't really have the possibility to indicate that it doesn't know the return type of a function. The absence of DW_AT_type for a DW_TAG_subprogram indicates a void function. Indeed the debug info generated by -g1 for malloc looks like: $ readelf -wi /usr/lib/libc.so.38.4: ... <1>: Abbrev Number: 2 (DW_TAG_subprogram) DW_AT_name : (indirect string, offset: 0x6484): imalloc DW_AT_decl_file : 1 DW_AT_decl_line : 1123 DW_AT_low_pc : 0x67ca0 DW_AT_high_pc : 0x67d9f DW_AT_frame_base : 1 byte block: 57 (DW_OP_reg7) ... My proposal to deal with this issue is to check in valops.c:find_function_in_inferior() whether the function is prototyped or not. If the function isn't prototyped, fall back on the code that's already there that uses the minimal symbol info and creates the return value type "by hand". Mark Index: ChangeLog from Mark Kettenis * valops.c (find_function_in_inferior): Only use full symbol info if it is prototyped. Index: valops.c =================================================================== RCS file: /cvs/src/src/gdb/valops.c,v retrieving revision 1.161 diff -u -p -r1.161 valops.c --- valops.c 27 May 2005 04:39:32 -0000 1.161 +++ valops.c 4 Dec 2005 18:44:39 -0000 @@ -141,37 +141,36 @@ struct value * find_function_in_inferior (const char *name) { struct symbol *sym; + struct minimal_symbol *msymbol; + sym = lookup_symbol (name, 0, VAR_DOMAIN, 0, NULL); if (sym != NULL) { if (SYMBOL_CLASS (sym) != LOC_BLOCK) - { - error (_("\"%s\" exists in this program but is not a function."), - name); - } - return value_of_variable (sym, NULL); + error (_("\"%s\" exists in this program but is not a function."), + name); + + if (TYPE_PROTOTYPED (SYMBOL_TYPE (sym))) + return value_of_variable (sym, NULL); } - else + + msymbol = lookup_minimal_symbol (name, NULL, NULL); + if (msymbol != NULL) { - struct minimal_symbol *msymbol = lookup_minimal_symbol (name, NULL, NULL); - if (msymbol != NULL) - { - struct type *type; - CORE_ADDR maddr; - type = lookup_pointer_type (builtin_type_char); - type = lookup_function_type (type); - type = lookup_pointer_type (type); - maddr = SYMBOL_VALUE_ADDRESS (msymbol); - return value_from_pointer (type, maddr); - } - else - { - if (!target_has_execution) - error (_("evaluation of this expression requires the target program to be active")); - else - error (_("evaluation of this expression requires the program to have a function \"%s\"."), name); - } + struct type *type; + CORE_ADDR maddr; + + type = lookup_pointer_type (builtin_type_char); + type = lookup_function_type (type); + type = lookup_pointer_type (type); + maddr = SYMBOL_VALUE_ADDRESS (msymbol); + return value_from_pointer (type, maddr); } + + if (!target_has_execution) + error (_("evaluation of this expression requires the target program to be active")); + else + error (_("evaluation of this expression requires the program to have a function \"%s\"."), name); } /* Allocate NBYTES of space in the inferior using the inferior's malloc